On May 27, NASA astronauts Bob Behnken and Doug Hurley are expected to become the first humans to ride a Dragon. The two astronauts will catch a ride to the International Space Station in SpaceX’s Crew Dragon capsule as part of the Demo-2 mission, the final test before NASA officially certifies the vehicle for human spaceflight. It will be the first time in nine years that NASA astronauts have launched to space from the US—and the only time they’ve ever flown on a commercial rocket.

Rocket about to lift off

The WIRED Guide to Commercial Human Space Flight

Everything you need to know about Blue Origin, SpaceX, Virgin Galactic, and what actually happens to your body if you go live in space.

SpaceX has spent more than a decade preparing for this mission, and the company has had its fair share of setbacks. They’ve had parachutes fail and test capsules explode, but each of these failures helped the company make its crew capsule even safer than before. The Demo-2 mission signals that NASA officials believe the Crew Dragon is finally reliable enough to safely carry humans to and from orbit. Still, Demo-2 is a test flight—so what happens if something goes wrong?

Like the Russian Soyuz capsule that has ferried all astronauts to the space station for the past decade, SpaceX’s Crew Dragon is equipped with an abort system that can punt astronauts to safety if anything happens before, during, or after launch. But the devil is in the details, which is why NASA and SpaceX have spent a lot of time going over different abort scenarios for every imaginable contingency. WIRED spoke with current and former astronauts and NASA’s flight director for the mission to learn how they prepared for the unexpected. (SpaceX representatives did not respond to a request for comment.)

Pad Abort

About 3 hours before liftoff, Behnken and Hurley will roll up to the launch pad in a white Tesla. They’ll take an elevator to the top of the launch tower, walk down the end of the crew access arm, pop the hatch on the Crew Dragon, and climb inside. At that point, they’ll begin a series of system checks that determine whether everything is go for launch. A critical part of this process is arming Crew Dragon’s abort system.

There are three ways to trigger the capsule’s abort system once it’s turned on. The crew can pull a handle inside the spacecraft; mission control can send a remote command to the spacecraft; or the craft itself can automatically start the sequence if it detects a problem in the rocket. This will cause the eight small SuperDraco rocket engines on the capsule to fire and lift it away from the rocket.

A pad abort is mostly to protect astronauts from the risk of an explosion during the 45 minutes that the rocket is being loaded with propellant. A pad explosion has only happened once before in SpaceX history; in 2016, the company lost a Falcon 9 rocket and its satellite payload during fueling. “SpaceX has since done modifications to their design to help mitigate that,” says Zeb Scoville, NASA’s flight director for the Demo-2 mission. “But that’s exactly the kind of scenario a pad abort protects against.”

Still, it’s a brutal event for a spacecraft’s occupants. In a matter of seconds, the capsule goes from a standstill to rocketing skyward at about 350 mph. During the abort, the astronauts experience forces more than four times stronger than gravity, ascending about a mile and a half before the capsule splashes down in the Atlantic Ocean under parachute. It’s an extreme maneuver for extreme emergencies.

If the astronauts need to be evacuated in less dire situations, they can catch a ride to the ground on a zipline attached to the tower. For example, if the launch gets called off after the rocket is fueled, the normal process is to keep the astronauts in the capsule until the fuel is drained. Then they can come down the tower the same way they went up. But if there’s a problem draining the propellant, it’s important to get the crew away from the live rocket ASAP so the problem can be fixed. It doesn’t make sense to put the astronauts at risk by doing an abort, so instead they use the zipline to make their quick getaway.

In-Flight Abort

The Crew Dragon’s abort system stays armed for its entire journey into space. After liftoff, Scoville says that the decision to abort is made by the Crew Dragon’s software, because anything that goes wrong will happen in a fraction of a second. “You can’t count on the response time of a flight controller or crew to take those actions,” he says.