Insect cocoons almost always use silk to some degree, but the major materials composing the cocoon can include the larva's own hairs, twigs and leaves; in addition to fecal matter, wood chips or sand. Different species vary in materials their cocoons are made from and also their shape and location.
Insect larvae create cocoons to protect their pupae, or an immobile form from which they transform from worm-like larvae to their adult forms. They produce the silk for their cocoons from structures at the ends of their abdomens, which produce a glue-like material that hardens into silk. Silk is very strong, but for many species, it is just the glue that holds other constituents of the cocoon in place. Many insects, such as the majority of butterflies, don't use a cocoon, instead relying on the hard chrysalis, or outer shell of the pupa, for protection.
Creating a cocoon helps a pupa survive, but once the adult insect emerges, it needs to be able to escape. Different insects have a variety of mechanisms they use to accomplish this. Insects with biting mouth parts can chew their way free. Other insects exude a fluid that softens the cocoon, and then just push their way out. Others build structures into the cocoon that open easily from the inside.