I think the way it works for most most (maybe even all) insects is to use air to blow themselves up much like a balloon to get out of the egg or cocoon.
While an egg or cocoon might be airtight, it must also still remain air permeable. Everything must be able to breathe. So while there might not be a visible flow of air, like through an open window, oxygen and CO2 still make their way in and out all the time.
Also initially the insect might break the egg/cocoon open without extra air, just by simple mechanics, but once it's out it starts to pump air into itself.