The ovipositor is a tube-like organ used by some animals for the laying of eggs. In insects, an ovipositor consists of a maximum of three pairs of appendages. The details and morphology of the ovipositor vary, but typically its form is adapted to functions such as transmitting the egg, preparing a place for it, and placing it properly. For insects, the organ is used merely to attach the egg to some surface, but for many parasitic species (primarily in wasps and other Hymenoptera), it is a piercing organ as well.
Some ovipositors only retract partly when not in use, and the basal part that sticks out is known as the scape, or more specifically oviscape, the word scape deriving from the Latin word sc?pus, meaning "stalk" or "shaft".
Grasshoppers use their ovipositors to force a burrow into the earth to receive the eggs. Cicadas pierce the wood of twigs with their ovipositors to insert the eggs. Sawflies slit the tissues of plants by means of the ovipositor and so do some species of long-horned grasshoppers. In the wasp genus Megarhyssa, the females have a slender ovipositor (terebra) several inches long that is used to drill into the wood of tree trunks. These species are parasitic in the larval stage on the larvae of horntail wasps, hence the egg must be deposited directly into the host's body as it is feeding. The ovipositor of the giant ichneumon wasp is the longest egg-laying organ known among biologists.
The stings of the Aculeata (wasps, hornets, bees, and ants) are ovipositors, highly modified and with associated venom glands. They are used to paralyze prey, or as defensive weapons. The penetrating sting plus venom allows the wasp to lay eggs with less risk of injury from the host. In some cases the injection also introduces virus particles that suppress the host's immune system and prevent it from destroying the eggs. However, in virtually all stinging Hymenoptera, the ovipositor is no longer used for egg-laying. An exception is the family Chrysididae, members of the Hymenoptera, in which species such as Chrysis ignita have reduced stinging apparatus and a functional ovipositor.
Members of the Dipteran (fly) families Tephritidae and Pyrgotidae have well-developed ovipositors that are partly retracted when not in use, with the part that sticks out being the oviscape. Oestridae, another family within Diptera, often have short hairy ovipositors, the species Cuterebra fontinella has one of the shortest within the family. 
Female bitterlings in the genus Rhodeus have an ovipositor in the form of a tubular extension of the genital orifice. During breeding season, they use it when depositing eggs in the mantle cavity of freshwater mussels, where their eggs develop in reasonable security. Seahorses have an ovipositor for introducing eggs into the brood pouch of the male, who carries them until it is time to release the fry into a suitable situation in the open water.
A female fly in the family Tephritidae, with the ovipositor retracted and only the scape showing.
Female Megarhyssa laying eggs with her ovipositor.