It's possible that something could have contaminated the plastic before it was sealed or that some opening already existed, allowing the insects access.  However, in many cases, maggots and other pests can gain entrance by "hitchhiking". This is when an unsuspecting person carries them inside on their clothes or belongings.  Additionally, adult flies can sometimes find tiny gaps and lay eggs which will eventually hatch into larvae (maggots). Inspect all bags carefully before sealing them up to prevent maggot infestations from occurring in food storage bags or containers.  This includes checking for any small holes or tears that might allow pests inside and proper cleaning and drying, so nothing foreign gets trapped between layers of material.  Also, avoid storing items near garbage cans or compost heaps since these are breeding grounds for flies.