With an estimated 10 quintillion individual insects alive on earth, it's probably only a matter of time before a few of them wander into the cupboards. Since cupboards store food, it's generally not a good idea to treat a cupboard infestation with harsh commercial products. Cupboards can be treated naturally, often with products that the average homeowner already has on hand.
Foods and Spices
Depending on what species has infested your cupboard, you can try putting various foods and spices wherever the bugs are. Ants are very common cupboard pests, especially in the cupboards where sweet goods like sugar are stored. A few pieces of cucumber or cucumber peeling will act as a natural repellent for them. They also are repelled by strong spices such as cinnamon or cayenne, so tapping a little onto the base of the cupboard or placing a small container of spice near a potential ant entryway is something to try. For other pests, you can try lemon peels, garlic and coffee grounds.
Some insects have aversions to particular herbs and plants; usually this has to do with the fact that the insect somehow can sense that the herb would be toxic based on their chemistry. For example, cockroaches can be deterred from entering cupboards with a little catnip. You also can try bay leaves, mint, lavender and rosemary. To make herb sachets, crush these herbs by rolling the leaves in your hands. Then put a little bit of the herbs onto small circles of a breathable cloth such as cotton. Bring the edges of the circles up and tie the circles closed with some string or twine. Place the sachets in the cupboards wherever you have insects.
Some insects are resistant to food, spice and herb treatments. These insects can be affected by borax, a household cleaning agent that has a very low toxicity for humans. Mix borax, honey and sugar together and put the mixture in a small container in the cupboards. The insects will eat the borax or carry it back to their colony. This works best for insects that are attracted to sweet substances, such as ants. You can modify the mixture based on what infestation you have---simply put something that your particular insect eats into it.
Moths are common cupboard pests that are particularly troublesome due to their ability to fly. Use cedar chips to get rid of these insects.