Ants cross a strand of spider silk without 2-pyrrolidinone (top), but avoid the strand with the repellent (bottom).
Adapted from Figure 1 of Zhang et al 2011.
Web-weaving spiders want to attract and entrap insects, but ants can be formidable predators themselves, so some spiders have evolved a mechanism to prevent ants from traversing the strands of silk:
[Shichang] Zhang found that the [golden orb-web] spider coats its silk with a chemical called 2-pyrrolidinone. He took some of these threads and strung them across a box, turning them into bridges that ants would have to cross to reach some bait. If Zhang washed the 2-pyrrolidinone away, the ants would happily traverse the silk. If he left the chemical on, they rapidly retreated at the slightest touch...Further details at Not Exactly Rocket Science. Image adaptation credit Myrmecos.
The same chemical drove off three different species of ants, including the widespread pharaohs. It appears to be a natural part of the ants’ repertoire: some species use it as part of their alarm pheromones, while others have it in their poison glands. It’s probably used by other spiders too. 2-pyrrolidinone is made from another chemical called GABA, which is found on the webs of at least four other spiders. Perhaps these compounds are part of an ancient defence system that orb-weaving spiders use to secure their homes from intruders.