Slugs and snails are a major threat to mushrooms outdoors. To prevent them access, sawdust, lime powder or ashes can be spread around logs. Beer traps can also be used. Moreover, small rodents also have to be prevented the access, since they like grain spawn.
The most common pests indoors are fruit flies, which can be most effectively eliminated by using yellow sticky traps hung near the lights (Picture).