TSA agents are known for stealing valuable things from passengers' luggage, either checked in or carried on. Is there way to avoid this? If so, what is the best way?
As for protection against any kind of breach: don't be an easy target.
It is extremely unlikely for the TSA to steal your belongings. Nevertheless, it does happen and you can protect yourself against it in multiple ways.
While there is nothing you can do to stop them from taking your stuff, you can make it not worthwhile. Who'd take a chance of being fired for a pair of socks or some toothpaste? Pack nothing valuable and/or easily resellable in your checked luggage.
Now, if you have to pack something valuable, put it in a way that a thief can't easily slip it in their pocket. Put it in a box or make sure it's big. Do not put it in a leather container. Leather can't be scanned through properly and can result in your luggage being checked out. In fact, it could be helpful to avoid leather in your luggage altogether. The less likely your luggage is to be noticed, the less likely it is your things get stolen.
This luggage goes through the scanner the same time as you do, so is a little easier to keep an eye on. I would also recommend putting your valuables in here. A thief would have the opportunity to steal your belongings while you are moving through the scanner. To protect yourself from having this happen, put your belongings in a way that nothing can be slipped out in the time it takes you to move through the scanner and have the pat-down if necessary. This is not more than a minute at worst. A couple locks or zip ties should provide good enough protection. Make sure that you are able to open those when requested though!
I posted this image before of an airport employee trying hard and failing to get into a gate checked bag:
So if you use a Pelican bag (this was a Pelican 1514) with TamperSeal hasps, it's pretty much a given noone will be able to casually open the bag and casually take this or that out. Not even with a hammer and a chisel or such, as visible :D The imaginary scene where a TSA employee uses an angle grinder at the checkpoint to get inside a bag is a matter of CollegeHumor videos, not reality.
Of course this is just for carry on, if you check it in the TSA has master keys and can open it and then casually forget to lock them back which causes the hasps to get lost which happened to me -- but still this is your best bet if you need to check in something valuable.
This is a little tongue-in-cheek, but if you really have something valuable that you need to take with you pack it with a firearm. Firearms are locked with personal locks. They may ask to inspect it with you present, but then you put your own locks on it. The other advantage is when you arrive at your destination an employee will bring the gun case to you. They also check your ID to make sure you're the proper owner of the firearm.
This would work in the US, but if your traveling overseas it might not be an option.
Run a cable through all your valuables so the thief has to take all of them as one large bulky unit. That will make it too obvious. Put self adhesive eyelets on your cell phone, laptop, camera, etc. and run a cable so they are all connected. I had TSA steal my ipod before and the other agents covered for him. No more.