There's a rainforest tree frog embryo that knows how to hit the exits early and hatch prematurely when it's feeling threatened, and a new study suggests the mechanism behind the magic.

In research published in the Journal of Experimental Biology, scientists with the Smithsonian Tropical Research Institute (STRI), in Panama City, Panama, offer an explanation for how the red-eyed tree frog (Agalychnis callidryas) manages to break free of its jelly-coated egg up to two days early if it's in danger.

It's not all doom and gloom, though. The embryos are actually well attuned to their surroundings, especially vibrations that spell trouble.

"Most people think of embryos as fairly passive," said STRI research associate Karen Warkentin in a statement. "But evidence keeps accumulating that embryos of many species are actively engaged with their world, not only receiving information but also using it to do things that help them survive."

That brings us to the embryo's escape artistry, and how the future frog avoids becoming a snack.

The STRI researchers captured the frog embryos on high-speed video as they performed their escape maneuvers.

In this video with a parrot snake, you can see how the embryos escape the cluster as the reptile feasts (Video credit: Michael S. Caldwell and Karen M. Warkentin):

The big question, of course, is how are they doing it? The scientists suggest in their study that the tadpoles squirt an enzyme that blows a hole in the egg once the future frogs are ready for their getaway.

"They do a shaking behavior while releasing enzymes from glands concentrated on their snouts," Warkentin explained. "That movement seems to push them, snout-first, against the hole the enzyme makes in the egg membrane. Then they muscle their way out by using big, S-shaped thrashing movements."

In this final video, Warkentin summarizes the process in detail, including her team's discovery of the hatching glands themselves, thanks to scanning electron microscopy:

It's tough to gauge from the videos just how fast the escape-hatchings are taking place. The researchers say it takes anywhere from 6 to 50 seconds, with 20 seconds being the average time to break free. Outside of the laboratory, they added, an escape can take place even faster than that.