Given a comfortable, or even nourishing, environment, rodents and other animals may be attracted.
Rats are probably the most undesirable pests. In a hospitable environment with plenty of food, they can multiply very quickly and become disease transmitters. So it is crucial to keep high-protein and fatty food wastes out of compost piles in areas where pests may be a problem. Meat and fish scraps, bones, cheeses, butter, and other dairy products should be excluded if pests are a problem. Bread and other high carbohydrate or high-sugar wastes can also attract pests.
Many flies, including houseflies, can spend their larval phase as maggots in compost piles. To control their numbers, compost piles with food in them must be turned frequently to encourage heating (larvae die at high temperatures). To prevent flies piles can be covered with finished compost or dry, high carbon material, like straw.
Food waste can be incorporated into the center of a compost pile, rather than on the surface, to avoid pest problems. Pest proof sides, bottoms, and covers may also be installed on compost units to help control pests. Bins built with side and cover openings less than two inches will discourage raccoons, skunks, and other large animals. Where rats are a problem, use hardware cloth with openings 1/2 inch or less to enclose sides, cover, and bottom.