It sounds magical; a caterpillar that has built a cocoon that could pass as a tiny palace forged from ice.

A brilliant white cocoon, that glimmers and shines, of a type that has never before been seen.

We know of no other cases from anywhere in the world of a caterpillar making a cocoon out of flakes of resin

A structure, in which the caterpillar can live and transform its very being, that has special powers, capable of warding off deadly invaders.

A place to live that is totally new to science, forged by a creator whose identity remains a mystery.

The caterpillar and the cocoon it made are real, and have just been discovered by scientists, who have published details in the Journal of Natural History.

One day I spotted this strange red caterpillar behaving oddly on a patch of resin on the trunk of a tree

The caterpillar was discovered in the forests of Borneo, by a research team led by Professor William Symondson of Cardiff University in Wales, UK.

The cocoon is so special because it is made from resin, a sticky substance exuded from trees that hardens over time. No other butterfly or moth is known to make a cocoon from such material.

Caterpillars build cocoons around themselves as a protective structure. Inside they pupate and metamorphose into their adult winged form.

The cocoon discovered by Prof Symondson and his team is built from two separate walls, which the caterpillar weaves together using silk.

But it also has a unique set of protective features.

The walls are covered in a series of sharp spikes, forged from the edges of resin flakes. This physical barrier makes the caterpillar hard to reach, protecting it from predators.

The resin is also impregnated with deadly substances that may poison those trying to breach it.

Most caterpillars spin cocoons from silk. A few integrate bits of plants, or faecal matter, to better disguise their home. Some add body hairs that can be irritating to touch.

Serendipitous discovery

Prof Symondson described how he stumbled upon the unique caterpillar.

“Every year I go out to Borneo, to our field station, Danau Girang, on the Kinabatangan river,” he told BBC Earth. “My speciality is entomology and I take groups of students into the forest to look at the amazing invertebrates, from gaudy butterflies to scorpions.

It is a wonderful piece of evolution

“One day I spotted this strange red caterpillar behaving oddly on a patch of resin on the trunk of a tree, pointing it out to the students. The caterpillar was mainly bright red, which caught my attention, and hairy. I came back at intervals during the day and photographed the various stages of construction of the cocoon.

“I had never heard of any caterpillar constructing its cocoon out of resin but thought at the time that it must be a well-known behaviour. When I got back to the UK I first searched the literature but could find nothing.

“I then contacted several people at the Natural History Museum in London, including the author, Jeremy Holloway, of the multi-volume books on the Moths of Borneo, but none had seen or heard of such behaviour before.”

The caterpillar’s bright red colour holds clues to its behavior. Bright colours are often used by animals, including insects, to indicate to predators that they are toxic, and not worth attacking.

We still do not know the species

“What often happens is that the animal extracts poisons from the plants it is eating and then stores those in its tissues as a defence.

“This was one reason why we analysed the chemical composition of the resin that it was using to construct its cocoon. The resin proved to be loaded with poisons and antifeedants.”

“We know of no other cases from anywhere in the world of a caterpillar making a cocoon out of flakes of resin,” he told BBC Earth.

The caterpillar’s discovery raises some interesting questions about how it came to utilise such a novel strategy.

If we could find a cocoon with the pupa still inside it we could hatch it out and the mystery would be solved

“It is a wonderful piece of evolution, because the resin is highly toxic and it makes you wonder how this species of caterpillar first started to use such a dangerous material.

“Relatives of this moth make cocoons out of pieces of bark and therefore it is likely that individuals that first built in a proportion of resin into their cocoons, as well as the bark, survived better. The resin not only hides the pupa well but also any inquisitive predator, bird or insect, has to get past a highly toxic barrier. Few are likely to be able to do so.

The identity of the caterpillar, however, remains unknown.

“We still do not know the species. Searches in the same area have failed to find another example of this lepidopteran - if we could find a cocoon with the pupa still inside it we could hatch it out and the mystery would be solved.”

Prof Symondson has form when it comes to discovering odd new creatures.

“Keep your eyes open and you too can make new discoveries,” he advises.

“A few years ago we discovered the Ghost Slug, which became one of the top 10 new species discoveries of the year. It was completely new to science.

“We found it in a back garden in Cardiff, so you don't have to go to exotic places to find something new. But if you do go somewhere exotic on your holidays take an interest in what's around you, including the creepy crawlies.”

Images published courtesy of William Symondson and reprinted by permission of Taylor & Francis Ltd.

"Bornean caterpillar (Lepidoptera) constructs cocoon from Vatica rassak (Dipterocarpaceae) resin containing multiple deterrent compounds" is published in Volume 49, Issue 9-10, pages 553-560 of the Journal of Natural History.

Follow Matt Walker and BBC Earth on twitter.