Get a job that requires you physically be there. You can't outsource the fry guy to India. Then the question comes back to whether your job can be replaced by a robot or computer.
Or, be the guy everyone wants. I know a pile of the /. crowd hate dealing with other people and would rather just talk to the computer, but that's basically the gist of the whole offshoring thing - if you're someone people don't see or interact with directly, it doesn't matter if you're here, or India.
So be the guy people talk to - especially customers. If you're dealing with customers, and you establish a rapport with them, quite likely they will try to follow you. This is especially if you're dealing with trust - if customers trust that you can deliver the goods, and are basically honest, they will seek you out.
We ran into this issue with a customer - the customer wanted to do a side project, and we were unable to do so (lacking the required skills, or so we thought), so they were going to contract it out. But they're uncomfortable - being the product in question is part of their "secret sauce" and they really don't want to risk it getting out there.
We're presenting ourselves as people they've already worked with, and as such, they already trust (me in particular who actually worked with them). If they trust me, they can trust my decisions, so if I bring in someone else from the company, they would be satisfied if I'm happy with them to extend that trust.
No, I do not work in sales or marketing, I'm just an engineer who doesn't hide in a dark corner of the office. I put myself front and center with the customer. Yes, it also means it's a PITA because I don't get to often touch the stuff as much as I'd like thanks to meetings and documentation and other project work, but it's hard to offshore the person the customer trusts to handle their work. Bring them a new face without my approval and they're rightly worried. And yes, if I'm attempted to be offshored, I will give them the training, but not the trust, probably because most likely, I don't trust them myself.
You put the face to the customer. If you're some anonymous engineer in the back no one sees, well, it doesn't matter if it's here or elsewhere, no one can tell the difference. But if you're a visible presence, and customers know you, it's a lot harder to have your work passed to someone else. Customers know when you don't trust the new guy, and customers hate it when someone they know and deal with productively gets swapped out for an unknown. Especially risky near the end of a contract since they may not have the rapport to renew and just cancel the whole thing.