So the vagus nerve, when you sense that you are about to eat, stimulates your stomach to release enzymes that help break down what you intake. This leads to a feedback chain that releases and inhibits other enzymes down in your intestines to further break down this food.
As for the microbes that make up our gut Flora, the simple answer is: they have different enzymes that break things down. They may have an enzyme that adds a chemical group to a drug, activating it or inactivating it. It's far more complicated, and not something I'm very knowledgeable about.