How are Maggots Sterilized (Disinfected)?
History
Ambroise Paré is credited with being the first to note his observations on Maggot Debridement Therapy (MDT) in the 1500 though it is a technology that has been used for centuries (reference). It wasn't until the 1920's that therapeutic experimentation with maggots was instigated by William Baer, a clinical professor in orthopaedic surgery at the Johns Hopkins University in Baltimore, Maryland, whose unorthodox methods were successful in the treatment of osteomyelitis and pyogenic wounds. He is also considered the father of modern MDT since he was the first to devise a way to sterilize maggots (reference).
Procedure
In addition to removing necrotic tissue from the wound (a procedure known as debridement) maggots have also been proven to disinfect wounds, promote healing, and inhibit a pesky substance known as biofilm from forming on the wound bed. Maggots are nature’s cleansers, showing up to remove dead tissue and promote healing (reference).
Currently Lucilia sericata, or the greenbottle blowfly larvae is preferred for MDT because

Firstly, larvae have been shown to debride wounds with extremely low
probability of myiasis upon clinical application. Larval secretions
have been shown to help in tissue regeneration. L. sericata have also
been shown to lower bacteremia levels in patients infected with MRSA (reference).

Sterilizing maggots
In early applications, sterilizing the larvae was a major problem. Doctors had to first bathe the eggs in bleach and then soak them in mercuric chloride or formaldehyde. The bandages, gaudy and cumbersome for the patients, were held in place with either surgical tape or Unna’s paste—made of zinc oxide, gelatin, glycerine, and water. Other problems that doctors faced included the maggots escaping during the application process and the leakage of toxic waste secreted by the maggots into the wound, which led to infections such as tetanus. Today, commercial and research laboratories produce sterile larvae. And instead of the bulky gauze bandage, a form-fitting cast with a nylon net to corral the larvae is placed over the wound. An absorbent pad put on top of the netting soaks up the larvae’s toxic waste products. The number of larvae used has also changed. Early prescriptions ranged from 5–6 maggots for a fingertip injury to 500–600 for a more serious wound. Today, the scientific standard of 10 larvae/cm2 is used (reference).
William Baer proposed a method to produce sterilized maggots and it is understood that sterilization has to start from the egg stage in itself (reference). The sterilization solution that he proposed was.

Stock Solution of bichloride of mercury, strength one in 1,000 parts.
Stock Solution of fifty per cent. ethyl alcohol. Take equal volume of
each Solution, mix, and add one-half of one per cent. chemically pure
hydrochloric acid. The final Solution will contain bichloride of
mercury, strength one in 2,000 parts, twenty-five per cent. alcohol,
and one-half of one per cent. hydrochloric acid.

He did not sterilize the maggots as such but took care to feed it sterile food. His work can be read here. Another solution used for sterilization was  5 per cent solution of formalin plus 1 per cent sodium hydroxide (reference).  Sterilization of maggot larvae in itself was found to be hard with some success being reported (reference). Current maggot sterilization techniques include.

UV Sterilization
Rapid washer sterilization
Egg to maggot sterilization (reference)

There is no first generation that has been detailed as such. Mostly sterilization starts from the egg stage. As far as bacteria in the gut is concerned, if sterilization is carried out well, it has been found that there is a significant decrease in any harmful bacteria present (reference). Most details of sterilizing maggot larvae is given in this paper. Consider reading this paper as well.