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.
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.