I cannot speak of all possible gas medicines. But there is a class of them which is indeed low risk and over the counter. These are silicones, and they work in a purely mechanical way, not getting absorbed by the body.
These silicones are the same stuff which you get in hair conditioner. They are quite inert chemically, and all they do is to change the surface tension of the liquid it is dissolved in - it becomes slippery, and if gas is pumped into it, it cannot form a bubble. As a result, it does not foam.
The bacteria in your intestine presumably continue to produce gas, but it quickly passes to its now-slippery contents, instead of being trapped and expanding them like the head of a poured beer. It does not exert painful, rumbling pressure anymore, and exits the intestine in small, less noticeable portions instead of creating mini-explosions.
For a reference, you can see this patent describing the mechanism of action of simethicone tablets: http://www.google.com/patents/US5612054.