Caterpillars grow and develop to their maximum size, then prepare to form a cocoon. Many changes are required. The pupa stage of most Lepidoptera is immobile, so the caterpillar must select a site for pupa formation. Many butterfly caterpillars make their pupa (called a chrysalis) while tied to the stem of a plant by a silk thread. Caterpillars of the tobacco hornworm will dig a nest in the soil. Caterpillars reared in captivity will exhibit their wild behaviors and a rearing process must accommodate them. Butterfly caterpillars may be given vertical sticks as sites for pupation. Caterpillars of the tobacco hornworm will start digging through their food in an attempt to make an underground nest. This process is messy, so the food is typically removed and replaced with a tissue. The caterpillar can chew the tissue and make a nest.A feeding caterpillar has a gut full of food that may contain pathogens. The caterpillar purges its gut and secretes enzymes that can destroy remaining pathogens. The food occupies a significant space inside the caterpillar. Purging the gut will cause the caterpillar to shrink.
As the caterpillar begins forming its pupa, the caterpillar cuticle separates from the cells below. The caterpillar becomes less active and incapable of crawling. The cuticle of the pupa is formed under the cuticle of the larva. Upon close observation, the newly forming pupa cuticle can be seen through the cuticle of the larva. When it is time to molt the larval cuticle will split along the dorsal surface and the pupa will emerge.