Ecologist Daniel Janzen has himself quite the caterpillar operation. In a patch of Costa Rican rainforest about the size of New York City and its suburbs, Janzen and 34 full-time staffers collect the crawlers and rear them into moths or butterflies—whatever the critter’s inclinations may be. The team is creating an inventory of sorts, netting some 40,000 caterpillars a year. But only 20 or so of those specimens will be the most gorgeous caterpillars on Earth.

These are the rare dalcerids, also known as the jewel caterpillars, creatures of such beauty that you might just want to wrap one in a gold chain and hang it around your neck, Mr. T style. Don’t, of course, and not just because of something called animal welfare: What appears to be glass is actually goo, a clever little adaptation for a caterpillar beset by the rainforest’s many enemies.

While they may look sizable in these big, pretty pictures, jewel caterpillars—which will turn into moths, by the way—are in fact tiny, typically around half an inch long. And that makes them real hard to spot. On top of that, they’re speedy as far as caterpillars go—take your eye off them and they can get away from you.

As for that fantastical body: You’ll notice that underneath the glassy goop are spikes coming off the caterpillar’s cuticle. These projections are fragile, and easily detachable. Break one off to squish it between your fingers and it’ll be real gooey and moist like Jell-O, but just give the caterpillar a touch, and the surface isn’t actually wet.

These detachable projections and their associated goo seem to be an elaborate anti-predator defense. “What we can see is that an ant or a wasp or anything that grabs it gets those pieces of projection its mouth, instead of the caterpillar,” Janzen says. While Janzen can’t say if the jewel’s goo is toxic or not, the stuff can gum up the mandibles of something like an attacking ant.

This probably serves to buy the caterpillar time. Remember that these creatures burn rubber—relatively speaking, of course. With the predator distracted, the caterpillar can make its getaway, perhaps even dropping off the leaf. “It's like if somebody was trying to grab you and your shirt was break-away,” says Janzen, “so that he gets a piece of cloth and you keep running.”

Daniel Janzen

So what about some actual observations of this predator-prey interaction? Glad you asked (...or I asked...whatever). Because doing a science is fun, entomologist Marc Epstein and other researchers back in the ‘90s exposed jewel caterpillars to ants, with hilarious results.

Most of the time, the ants closed in to inspect the caterpillar with their antennae, but then moved along. A few, though, would venture a bite, ending up with a mouthful of goop that they would work frantically to dislodge. Some would even get stuck to the caterpillar without dislodging the gelatinous projections, I’d assume much to the concern of both parties involved. (This study, by the way, also couldn't definitively conclude whether the goo was toxic or not.)

Apparently it’s an effective defense, for jewel caterpillars have no qualms about meandering out in the open on the tops of leaves, whereas caterpillars without defenses tend to stick to the undersides. And that’s quite the gamble for the jewels, since the forest stocks no shortage of not only marauding ants, but other fiends like wasps and birds.

Interestingly, the jewel caterpillar has close relatives, the limacodids, that deploy a different countermeasure: nasty stinging spines. These caterpillars are slower than their bejeweled cousins, and that you might expect, since the jewel caterpillar can only temporarily incapacitate its foes. The limacodids, however, can devastate their enemies, and need no such haste. “What they're saying to you is, ‘Hey, I'm dangerous, you touch me and you're gonna get hurt,’” Janzen says. “They're not in a hurry to move on.”

Daniel Janzen

So what’s with all this caterpillar violence? The problem is that being a slow, squishy piece of meat is not ideal if survival is among your interests. So caterpillars can try their luck hiding on the undersides of leaves, or they can venture out into the open, countermeasures in hand. Stinging works great for the limacodids, sure, but the jewel caterpillar has evolved something rather more gelatinous.

It turns out, though, that even the seemingly impenetrable defense of the jewel caterpillar has its weakness.

Enter the maggot of the parasitic tachinid fly. Like mammalian predators would flip over a porcupine to attack its underside, the maggot probably gets under the caterpillar and drills through its unprotected belly. It takes up residence in its host, and waits. The caterpillar keeps feeding, putting on more and more weight—and more and more food for the invader living inside it.

Daniel Janzen

Then, “somewhere in there the fly maggot clicks on and quite voraciously and in a very short period of time literally consumes the inside of the caterpillar,” Janzen says. “So now you have a big maggot inside, and that big maggot then in most cases drills back out through the cuticle and pupates in the soil, but in some cases they pupate actually inside the remains of the caterpillar.”

In other cases, though, the caterpillar will have already itself begun pupating in its cocoon. Thus you may come across what you think is a pupating jewel caterpillar, when in fact it's a tachinid that's nice and snug inside. (A certain parasitic wasp goes about life in a similar manner, only its mother injects it and up to 80 siblings into a single caterpillar. They feed, erupt out of the host, and mind-control it into guarding them as they spin their cocoons. Ya know, like ya do.)

It’s some clever parasitism, but no way to send off the world’s most beautiful caterpillar. So here’s another picture of one strutting its stuff.

Shine on, you crazy living diamond. And good luck out there.

Daniel Janzen

Browse the full Absurd Creature of the Week archive here. Know of an animal you want me to write about? Are you a scientist studying a bizarre creature? Email matthew_simon@wired.com or ping me on Twitter at @mrMattSimon.