In addition to the millions of microscopic bacteria that decompose the organic waste in a compost bin, a variety of larger creatures helps produce the finished product, including soldier flies. Although beneficial to the composting process, soldier flies can lay eggs in the compost, producing maggots--also called larvae--which have the singular ability to disgust even the most enthusiastic composters. Grayish-white in appearance, soldier fly maggots are approximately an inch long and wriggle actively, especially when exposed to light. Since these maggots thrive on nitrogen-rich materials, one of the keys to eliminating them from your compost is maintaining a proper balance of carbon materials in the bin.
Check the moisture level of the compost bin. The aim for compost bin is for it to be the consistency of a wrung-out sponge. If the compost is dripping wet it's too moist.
Add carbon-rich materials such as shredded newspaper, cardboard, dead leaves, straw or old hay, to the compost bin to reduce the moisture level and to offset the amount of nitrogen materials.
Cover the nitrogen materials in your compost with at least 2 to 4 inches of carbon materials. Bury food scraps and other nitrogen-rich materials thoroughly in the bin.
Feed maggots in the compost bin to the birds to help control them. Dump the larvae in a location that is away from buildings so birds can easily find them.