Warp Core Ejection
A warp core breach is an extremely dangerous situation, so a number of safety procedures are in place to deal with such an eventuality.

Warp Core Ejection The warp engines function by annihilating matter and antimatter, generating an enormous amount of energy. If the warp containment field collapses or the warp core becomes unstable, it can result in a massive explosion that could easily destroy the ship. As a result all Federation starships have been designed so that the warp core can be safely ejected in case of an emergency.

Starfleet protocols require that the warp core be retained if at all possible, and so power and fuel supplies are automatically sealed off at points upstream from the damaged areas. A multilayered forcefield is then deployed in an effort to contain the unstable core. If these measures fail, the safety of the crew and ship becomes paramount, and the warp core must be ejected. The procedure for warp core ejection involves initiating a manual sequence or automatic computer activation. The order to eject a core can only be given by crew members with the necessary authoization, such as the captain, first officer, or chief engineer. The next step is to engage the ejection system, while the magnetic valves and transfer pipes connected to the warp core are dealt with automatically. When the order is given, the computer opens or blows out the matter-antimatter reacation assembly exterior hull hatch, which is located on the ventral side of the ship. The core is then forcibly ejected through this hatch with explosive charges.

Once the core has been ejected, it will not necessarily breach; it may cool down in space, in which case it can be retrieved. As the core will probably still be unstable, the crew have to perform repairs before locking on a tractor beam and reconnecting the core to the engineering systems.

Warp Core Ejection: Stage 1
The ejection of a warp core must be carried out quickly to avoid the destruction of the ship and crew. Strict protocols must be followed, beginning with a manual sequence initiation or an automatic computer activation by an authorized crew member. If the warp core dangerously close to breaching, the first thing the crew will do is stabilize it by cutting power relays and decoupling the dilithium matrix. If the warp core is unable to be stabilized, Main Engineering is immediately evacuated with the safety bulkheads closing off the section.

Warp Core Ejection: Stage 2
Following the order to eject the warp core, usually given by either the captain or chief engineer onboard, the computer automatically opens the matter-antimatter hull hatch on the exterior of the ship. When all the interior connections have been severed, the core is dumped through this opening using explosive charges. On most Starfleet vessels the ejection hatch is located on the underside of the engineering hull.

Warp Core Ejection: Stage 3
With the warp core floating in space, the ship can move away to a safe distance under impulse power. Once disconnected from the ship, the core may cool down and not breach. If this is the case, the vessel will return and attempt to retrieve and reinstall it. However, if the core does breach some starships are equipped with secondary components to build a temporary warp core in order to reach a Federation starbase.

Warp Core Ejection: Stage 4
The core may have to be repaired in space before it can be retrieved. It will probably drift several million kilometers away from the ship. If the warp core is salvageable, it is a relativately simple process to recover it using a shuttle or a tractor beam.