“It’s just a stupid song,” says a witch in the second episode of “Agatha All Along.” However, as viewers of the new Marvel series know by now, “The Ballad of the Witches’ Road” is anything but stupid. It’s a cultural touchstone for the centuries-old witches, an instruction manual for navigating the road and an infectious tune that’s become an earworm since the recent season premiere.

And in the fourth episode, the song transforms like the road itself, and what was once an ancient chant has become a head-banging — and heart-healing — ’70s rock hit. Creator and showrunner Jac Schaeffer promised that additional versions were still ahead.

“ ‘The Ballad’ is the backbone of the whole show,” she said. With each new version, “It’s less about the genre and more about the era and its significance to Agatha. So rather than doing what we did in ‘WandaVision’ — which was phenomenal, but it was quite cutesy, like we ran it through a filter every time — this is different because it’s ingrained and embedded in a way that’s far more about story than it is about window dressing.”

Schaeffer knew early on that the “WandaVision” spinoff series would set the characters in “different trials that are like witchy escape rooms,” each with varied wardrobe and production design, strong emotional breakthroughs and opportunities to play with perceptions of witches throughout history.

Anchoring it all with a song made sense, since “Agatha All Along,” the minute-long ditty that revealed Agatha Harkness’ (Kathryn Hahn) Westview villainy, went viral in 2021, spawning countless covers, remixes and an Emmy win.

“I love musical interludes in content where it’s not a traditional musical and it’s more world-ized,” said Schaeffer, citing the 1991 movie “The Commitments” and the 1996 movie “That Thing You Do!” as prime examples.

She tasked Kristen Anderson-Lopez and Robert Lopez — the “Frozen” and “Coco” composer-lyricists who created the “WandaVision” theme songs — with writing multiple, distinct versions of “The Ballad.” “Each version had to include some new and vital piece of information, and be changed enough to feel like a different song,” said Anderson-Lopez about the assignment.

The married songwriters created all of the song’s variations in a three-week period, making only minor tweaks to the lyrics for plot needs. “It was a multidimensional puzzle, each like its own little musical magic trick of, ‘Hey, same tune, mostly, same words, mostly. But listen closely, this time is different.’ ”

“The Ballad” is introduced in the series’ opening moments: Agatha herself is humming the tune, whether she realizes it or not. From there, remnants of the melody are peppered throughout Christophe Beck and Michael Paraskevas’ score, and a blues version plays over the pilot’s title sequence and is sung by Matthew Mayfield.

“That one is sung by a man, as a bit of a misdirect,” Schaeffer said. “I love watching things that scratch at my subconscious, so we made it so that when you hear them singing together in the basement (toward the end of Episode 2), it feels familiar somehow, like you already know it.”

That sacred chant version of “The Ballad” — performed by Agatha, divination witch Lilia Calderu (Patti LuPone), potions expert Jennifer Kale (Sasheer Zamata), protection witch Alice Wu- Gulliver (Ali Ahn) and Agatha’s neighbor Sharon Davis, aka Mrs. Hart (Debra Jo Rupp) — outlines, in poetic detail, that the legendary Witches’ Road is revealed when a coven sings it, unlocking the trials they must face to reach the end.

“It released us of this enormous expositional burden of explaining the road’s rules,” Schaeffer said. “We needed all these witches to be on the same page quickly, and because all witches were aware of ‘The Ballad,’ they already knew everything about it. Almost all of the world-building in the show, you can point to a word or a phrase in the song.”

Filming this version for Episode 2 “felt sacred,” said Hahn of the full-length, a cappella rendition, which begins with the witches visibly hesitant and ends with them holding hands and clearly connected.

“I’ll never forget that day. We ran through it together to get the master shots, but for coverage, each person sang their part of the harmony alone,” she recalled. “So all you heard were these beautiful, vulnerable notes by Sasheer and Ali, and then all of a sudden, you heard Patti, and oh my God, the power! And that was her holding back!”

“They were all singing as actors, not as vocalists, so there’s a rawness to the recording that’s really special,” added Schaeffer, who directed Episode 2. “And they all have such rich textures to their voices. It’s true to the themes of the show, where these witches have very distinct personalities, but they harmonize together on the day.”

The most drastic transmutation of “The Ballad” at the time was in Episode 4. The road puts the coven in a ’70s-era recording studio and specifically challenges Alice, the daughter of Lorna Wu, who recorded the most famous version of the ballad and, despite her drinking problem, was constantly on tour with her rock band, the Coral Shore (a reference to Alice’s mother in the comics).

The trial? To stop them all from getting burned at the stake.

“All signs point to a jam session,” Agatha concludes. “You should have burnt to a crisp years ago, but here you are, sullen and aimless, but alive. That’s because at any given moment, somewhere, someone is playing that song that you hate so much. Lorna’s ‘Ballad’ is a protection spell. It protected you.”

Adds Lilia, “And maybe now, it can protect us.”

“Up until this moment, Alice really didn’t know if her mother loved her because her mom was obsessed with performing this song for her fans, and died when Alice was just a teenager,” said Ahn of the reveal. “But the song is actually her mom’s way of loving her. That miscommunication between mother and daughter is a universal thing, but there is something particular about the lack of transparency that can happen between Asian generations.”

Pulling inspiration from Fleetwood Mac, the Eagles and Crosby, Stills, Nash & Young, the songwriters wrote Lorna’s version of “The Ballad” first. The piano-driven track had to work as both “a bitter love song full of pain and heartbreak,” said Anderson- Lopez, and a vow from a resigned parent to an estranged child.

“I had to put myself in a bubble of confidence because otherwise I would have been a puddle on the floor,” said Hahn.

Though sections of the studio keep bursting into flames, the members of the coven — this time with the still-unnamed Teen (Joe Locke) and Agatha’s mysterious rival Rio Vidal (Aubrey Plaza) in tow — each take up their own instruments.

Alice takes over the lead vocal during the bridge, playing more robustly and roaring with a newfound resolve, even when the winged demon (Jade Quan) lands on her shoulders and sets them ablaze. The unlikely catalyst for that climactic beat: Fleetwood Mac’s 1997 performance of “Silver Springs,” in which Stevie Nicks turns to Lindsey Buckingham and delivers the haunting song directly to her former flame, who inspired the composition.

“Something in her snaps, and it’s like she’s singing from the depths of her soul, it’s so electric,” said Schaeffer of the band’s footage. “Trying to channel that while also having a performer in a harness on Ali’s shoulders, how do we make the mechanics work and still feel emotionally impactful and not ridiculous? It came down to editing within the song, making sure the cuts felt right and, in the grand tradition of Bruce the Shark (from “Jaws”), limiting how much we see the demon so that we maximize scariness.”

In following episodes, “the evolution of the song is pretty amazing,” teased Hahn.