Ideally, a potting soil should be sterile, but in reality is very susceptible to getting bugs, especially fungus gnats, while being stored. I don't know any way to avoid this. I have seen hints on cooking/bbqing your soil yourself to sterilize, but never needed too. For fungus gnats, I use little sticky traps, and keep control of my watering to not overwater.