A protective covering for eggs and/or larvae produced by many invertebrates. For example, the larvae of many insects spin a cocoon in which the pupae develop (that of the silkworm moth produces silk), and earthworms secrete a cocoon for the developing eggs (see clitellum).