SPOILER ALERT: Proceed with caution if you have not yet watched “John Mulaney and the Sack Lunch Bunch,” streaming now on Netflix.

Children’s entertainment based on “existential angst and fear” might not seem like a natural combination on the face of it, but according to John Mulaney, that combination’s fueled the genre for as long as he can remember.

“A lot of entertainment that I consumed as a kid had a lot of either melancholy or dread, and it was not some undertone,” the comedian tells Variety. “Even things like ‘I know an old lady who swallowed a fly’ — every part of that [song] is odd and disturbing!”

And so as he set about building “John Mulaney and the Sack Lunch Bunch,” his new variety special for Netflix, co-written by Marika Sawyer (“Saturday Night Live”) with music by composer Eli Bolin (“Sesame Street,” “Co-Op”). They drew inspiration from musical influences including Burt Bacharach, Howard Ashman and Alan Menken, and Trinidadian calypso legend Mighty Sparrow. They turned to pieces like Maurice Sendak and Carole King’s “Really Rosie” and Harry Nilsson’s “The Point,” which were also fueled by catchy songs and extremely relatable anxieties. “As a kid, we watched movies like ‘Little Shop of Horrors’ and ‘Clue,’ and they didn’t seem inappropriate — and I don’t think they are,” Mulaney says. “But they had a lot of tension to them.”

They also assembled a cast of preternaturally talented children (the aforementioned “Sack Lunch Bunch”) to sing songs about feeling ignored, confused and melancholy. They threw in silly cutaway jokes and wonderfully weird turns from people like David Byrne and Jake Gyllenhaal, and even a brief aside called “Girl Talk with Richard Kind.” As Bolin puts it, the special’s goal was to follow in the footsteps of their childhood touchstones, which all erred “very funny, and a little dark.”

The only unscripted parts of the special are when they ask each kid castmember about their biggest fears, a choice Mulaney explains as coming out of some personal curiosity. As a kid, he says, “I remember being afraid and having to to just deal with it. And I wondered if that’s what they’re going through, too.”

Another of his and Sawyer’s goals was to make a special that both kids and adults could enjoy without condescending to either demographic: “We didn’t want it to be 5 jokes for kids and 1 joke for adults that wasn’t at all for kids,” as Mulaney puts it.

“The Sack Lunch Bunch” pokes fun at this particular trope in a sketch about a focus group for “Bamboo 2: Bamboozled,” a fictional take on the kind of nightmare animated movie that’s become a Hollywood staple. The sketch also pokes fun at these movies’ star-studded casts: At one point, Mulaney asks the children if they could tell that “Danny the Dodo” was voiced by “someone, but you couldn’t quite place him,” before revealing that the answer’s Jeremy Renner.

“I always found it bizarre that no expense was spared in getting huge movie stars into animated films,” muses Mulaney. “I’d see the poster and be like, ‘Does a kid care that it’s Luke Wilson?’ Angela Lansbury and Jerry Orbach were in ‘Beauty and the Beast’ and are very respected, but they’re not Brad and Angelina.”

With that in mind, the celebrity cameos of “The Sack Lunch Bunch” are extremely specific and catered to their talents. Broadway stars André De Shields and Annaleigh Ashford pop up to anchor tricky musical numbers (as a mysterious math tutor and “white lady sobbing on the street,” respectively). Natasha Lyonne joins the kids in sharing her biggest fears (including escalators, temperamental toilets and nuclear disasters). And two of the biggest scene-stealers — aside from the children themselves — are Byrne and Gyllenhaal, each turning in wildly weird and unforgettable performances.

Byrne’s number, performed with Lexi Perkel, has the two fighting for attention from a party full of oblivious adults with magic tricks, flashing lights, and matching “Frozen” costumes. The accompanying prog-rock song sounds like one Byrne could written himself, which was exactly the point. (Lifelong Talking Heads fan Bolin composed it, but says Byrne nonetheless shared some ideas and his own “general personal feelings of alienation.”)

“There’s a Talking Heads song called ‘Warning Sign,’ and it has this line in it: ‘Hear my voice, it’s saying something and I hope you’re concentrating,’” recalls Mulaney. “I always liked that line — so we just thought something about a kid’s frustration and a little of that very funny David Byrne, ‘I’m trying to be polite but I’m frustrated’ lyricism would go well together.”

All of that feels on point for Byrne’s particular brand — but Gyllenhaal’s number contrasts his own in such a beautifully unhinged way that it’s not at all an exaggeration to say that it might haunt your dreams for weeks after seeing it.

As “Mr. Music,” Gyllenhaal crashes in near the end of the special with a press-on mustache, and jacket that doubles as a xylophone. “I’m here to teach you about music!” he cries, eyes wild. He refuses a child’s offer of a clarinet (“Put away your skinny trumpet! Instruments are stupid!”) before launching into a jaunty calypso tune about how there’s “music here, music there, music, music, everywhere!” The only problem is, nothing he uses to demonstrate that fact — whether a pudding cup, leaky faucet, or fancy toilet — ends up making any sounds at all. Mr. Music’s ensuing breakdown is one of the most purely bizarre things on TV this year, period, and Gyllenhaal embraces the downward spiral so thoroughly that his mustache comes flying off by the end.

“It was pretty clear what [Mr. Music] was and that he would just be struggling,” says Mulaney of the writing process. “[But] until Mr. Gyllenhaal came in, the level of breakdown he was going to have was uncharted.”

(Later, when Gyllenhaal asked Mulaney who else they wanted to ask, Mulaney assured him that he was their “first choice in a world where we couldn’t have Harry Belafonte.”)

This number, unlike every other one in the special, had to be performed and recorded live as Gyllenhaal careened through over a dozen vignettes of failure. “It was really by the seat of our pants,” says Bolin — plus, given the premise, “if there’s any sound anywhere, you have to start and go back.”

But Gyllenhaal was so committed to the song and persona that it all came together, anyway. “When a great actor commits himself to comedy, and I say this very a reluctantly as a comedian that’s not a great actor,” adds Mulane wryly, “it’s funnier than any comedian could ever be. Every take he made a different choice, and the first one when he was pulling notes out of the air we were like, ‘This is the funniest thing we’ve ever seen and we’ve worked with many, many comic talents.’”

Eventually, the kids help a bedraggled Mr. Music relax and have some fun, despite his frustration (and several ridiculous injuries). Their final singalong turns a potentially sour experience into something joyous and hopeful, confirming that “John Mulaney and the Sack Lunch Bunch” is one of the year’s the strangest hours of television, with one of the biggest hearts.