Residents were forced to flee as the trees were set ablaze by fireworks shooting out the building in Saraburi province 72 miles northeast of Bangkok.
Four warehouses belonging to Pacific Pyro Company, which owned the factory, also caught fire.
It took 20 fire engines several hours to get the multiple blazes under control. Police evacuated homes within 1.8 miles of the factory for safety. It is thought nobody was working at the factory when the explosions began on Tuesday evening.
According to police no casualties were reported. An investigation into the cause of the incident is under way.