Fortunately, most military equipment is built with this idea in mind. The guns are made so that they will still fire when they are wet or when they have been dropped in the sand. Computers are designed to keep excess sand and moisture out so that they will keep working even when they are sitting on the back of a truck that is being shot at, not just when they are sitting on a desk in an office somewhere behind the lines. For computer equipment, heavy cases are developed to take all of the abuse so that the fragile parts inside of the casing are never harmed.
The certification process for this type of equipment is incredible. It has to be put through tests that are designed to destroy it, simulating conditions that are worse than what it will probably experience in real life, and it will only be sent out into the field if it passes all of these tests and demonstrates its reliability.