Contrary to popular belief, mothballs are not very effective at repelling snakes. The best way to keep snakes out of areas inhabited by pets and humans is to make the area less appealing to the reptiles.
Snakes can be kept away by keeping all food sources, such as pet food, stored in air-tight containers. Seal off all entryways to crawlspaces and basements, and cover all vents and drains that lead into homes and buildings. Snake-proof fences are also an option to keep out snakes from yards and gardens. Chemical snake repellents can be used, but these also pose risks to people and pets. If a snake finds an entry inside a house, mechanical traps and glue traps can be used to capture it.