Horntail adult females introduce wood-digesting fungi (e.g. Amylostereum) when ovipositing, which helps their grubs extract food value while feeding on the wood. Adult female Megarhyssa are able to detect the odor of these fungi, and once they land on the bark of an infected tree the Megarhyssa will walk along tapping the surface with their antennae (or "antennating") to further pinpoint the location of horntail grubs within the wood.
Once grubs are located, the female Megarhyssa positions herself with back legs extended and ovipositor perpendicular to the bark, and drills into the tree to deposit an egg on or near a horntail grub within its burrow (see videos here). While drilling the female wasp is immobilized and vulnerable to predation by birds.
When the Megarhyssa egg hatches it behaves as an ectoparasitic idiobiont, completely consuming the grub. It pupates within the burrow and emerges in the summer. (taken from Bugguide.net)