A developing frog embryo in its jelly-like egg mass can be quite the escape artist: When predators come calling, the red-eyed tree frog embryo can detect the threat and drop out of its egg to safety in a matter of seconds, even though it normally wouldn't be ready to hatch for several more days.

And for the first time, scientists have discovered how the embryos are wriggling out of harm's way.

Karen Warkentin, study co-author and a biology professor at Boston University, reported the unusual behavior in red-eyed tree frog embryos in an earlier study published in 2005 in the journal Animal Behavior. Warkentin recorded the embryos' responses to different types of vibrations. She noted that the embryos could tell the difference between vibrations caused by a predator and those caused by other types of disturbances such as raindrops, recognizing when certain types of touches on their egg membranes meant danger.

Related: Video: Tree Frog Embryos are Speedy Escape Artists

Undisturbed embryos would typically hatch after six or seven days. But if embryos felt a predator's touch as early as four days into their development, they would drop from their eggs — which were clustered together on leaves overhanging ponds — and fall into the water, where they'd swim away and continue their lives as tadpoles.

In the new study, the researchers delved into the biological mechanisms that enabled the embryos to escape so quickly.

A trick up their snouts

Most frog embryos release enzymes throughout their growth inside the egg, so that the membrane is gradually weakened over time, according to study co-author Kristina Cohen, a graduate student at Boston University who is studying ecology, behavior and evolution. But red-eyed tree frogs have another trick up their sleeves — or more precisely, their snouts.

"Red-eyed tree frog embryos store up that enzyme, so it can all be deployed at once and at any moment," Cohen told Live Science. The embryo's hatching glands are on its snout, so it can direct this concentrated jet of chemicals at a single target, quickly opening an escape hatch and making a swift getaway.

How swift? During actual attacks from predators, the researchers saw embryos hatch in less than 6 seconds, Warkentin said in a statement.

And their strategy is quite successful, Cohen added.

"After the fourth day of development, they can hatch rapidly, and they had about an 80 percent success rate escaping from snakes," Cohen told Live Science. It wasn't just snakes that the embryos could sense — Cohen explained that they observed similar evasive maneuvers in response to wasps, pathogenic fungus and flooding.

Their discovery casts embryos in a whole new light, Cohen noted, revealing them to be capable of far more complex behavior than once thought.

"We think of adult animals as doing interesting things, but embryos are seen as very passive — just waiting to hatch," Cohen said. "I think that this research will increase awareness of how they respond to their environment in adaptive ways."

The findings were published online June 15 in the Journal of Experimental Biology.

Copyright 2016 LiveScience, a Purch company. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.