SPOILER ALERT: Do not read if you have not yet watched the “USS Callister” episode of “Black Mirror’s” fourth season.

When Cristin Milioti first received materials for “Black Mirror’s” “USS Callister” episode, she had no idea just how timely the story would become — that of a young woman, harassed at work by male bosses but who topples the patriarchy in a virtual reality world to become the captain of a the spaceship. In fact, she didn’t even know that was the character journey for Nanette, the woman she would be playing in the fourth season of Netflix’s futuristic anthology drama.

“I was only given a couple of pages of the script,” Milioti admits, explaining that the two scenes she was given initially were when Nanette meets Robert Daley (Jesse Plemons) on her first day in the gaming company’s office and the scene on the ship where she rallies the crew by telling them she’ll blackmail herself in order to get to Daley’s refrigerator full of his co-workers’ DNA.

“I was not able to piece things together from those two scenes, but I knew I loved how it was written and I loved her, in particular,” Milioti says.

Noting that it is very important to her to play “fully realized women who are very strong,” Milioti points out the unpacking of its characters’ layers is what made “USS Callister” stand out to her.

“She’s so tough, but one can write her off at first as being this very sweet, meek women in the office who just has her head down and is trying to focus on her work and isn’t taken as seriously as she would like to be taken. But when push comes to shove, she can captain a ship. She has a strength in her that no one saw coming. She’s a spitfire,” Milioti says of Nanette.

The episode starts by following Plemons’ Daley, a beaten-down tech genius by day who enters a virtual reality world of his own creation by night to lead a space crew of his real world co-workers on missions modeled after a beloved show from his childhood (the fictional “Space Fleet,” which looks a lot like “Star Trek”).

“It’s supposed to be heightened. It’s supposed to be sort of phony in some way. And that’s when I realized we should really go all-out. We couldn’t hold back on this. We had to go fully ‘Star Trek’ on the way that it was shot, the way that we held the camera,” director Toby Haynes says. “We literally built a spaceship that had a ceiling in the studio, and when we put a ceiling in, we had to light it like the original ‘Star Trek.’ When we come in close we needed to get the full molding lights and the back lights and the key lights, especially for those Kirk-like close-ups [on Daley]. It was a language.”

While that virtual world first just feels like a way for the man to escape Daley’s lackluster reality, he begins to show abuses of power within that world — first with the way he treats his crew there and then through the reveal of how he got that crew in the first place. In the “real” world, Daley collected and copied his co-workers’ DNA, effectively creating digital clones of them that he trapped inside the confines of the virtual world. They have the consciousnesses and the memories of his still very much alive co-workers, but they are doomed to bide their time on the spaceship, awaiting Daley’s visits to go on missions and fearing his wrath when he arrives.

“We think he’s the protagonist at first — he’s the hero — but slowly we realize he’s the villain, and I thought that was so well done,” Milioti says. “He’s a bully. He’s bullied into being a bully, and it’s beautiful that they did that so you understand why he is the way he is, but it doesn’t make it right.”

Nanette is introduced a few scenes into the episode, as a new employee at Daley’s company who has to deal with two kinds of harassment not only from Daley but from another executive at his company (played by Jimmi Simpson).

“This is a woman, who has Jimmi Simpson’s character putting his hand on her lower back and even Jesse Plemons’ character wants to make it something sexual, but she just wants to work,” Milioti explains, adding that she “just wants to be taken seriously as a coder” but like so many who enter a hostile workplace faces micro-aggressive harassment and chooses to deal with it in a way that has her “keeping her distance but with a smile” so as to not cause more problems or to lose the job she loves.

“What started out as ‘I want to work with the man who inspired me’ becomes shut down because it’s inappropriate almost immediately,” MIlioti says. “So the way I tried to portray her in the office is as someone who is overwhelmed by the niceties that she has to insist upon herself in the business world. If she wants to get ahead, she has to just smile, and as opposed to just ripping the hand off of her back, she shrugs her shoulders. I tried to make her voice a little higher, too, because it’s that thing where you’re just like, ‘Oh gosh, sorry!’ when you really want to be like, ‘Don’t kiss me on both cheeks, we’re not in Europe!’”.

But after Daley overhears Nanette saying she doesn’t want to pursue anything romantically, he feels slighted and uploads a copy of her DNA to his custom program as well. A new version of Nanette awakens on the ship and struggles to adjust to the reality that she is stuck there while another version of herself lives out in the “real world.”

“When she’s on the ship, the stakes are so incredibly high for her, and she’s fighting for her life, so all of those niceties just go out the window, and she lets go of the bulls— and the need to be polite and smile, all of that,” Milioti says. “She actually realizes her greatest potential. It’s why she fights him, it’s why she makes fun of him. As much as she’s a prisoner in that world, she takes the filter off for the first time and says, ‘F— you.’ I think she’s the truest version of herself on that ship.”

Nanette leads a revolution of the others on the ship to wipe his custom program. It is a plan that requires them to reach out to the real world version of herself in order to break into Daley’s home and steal their DNA so that he cannot just upload new copies of them and start the process over. Haynes admits he was nervous about the end and at one point questioned if it wouldn’t be a more fitting, typical “Black Mirror” end if the final shot was on Daley, stuck in his chair in his apartment in the quote-unquote real world.

“Charlie said not every ‘Black Mirror’ has to end in such a dark place,” Haynes says. “He knows that he has this in his back pocket — an episode that will end in a more positive place. I think it will really surprise people to have something that has such a dramatic draw but ends so positively as ‘USS Callister.’ It really throws you around tonally and emotionally. At least, that’s what I tried to do, to take these characters — these avatars — in a virtual environment and make you feel for them, make you care about them, and come away with a kind of empathy.”

Nanette’s plan is also one Milioti feels reflects the reality she wants to see more of in the actual real world: “a woman in charge [fighting] against a small-minded, misogynist bully.”

“In the quote-unquote real world, she probably continues to be a team player and very sweet and keeps her nose to the grindstone, but in the fake world she becomes a captain and beats the super villain,” Milioti says. “It’s amazing. Something that starts out so bleak is able to turn into her own hero’s story, and I love that.”

“Black Mirror” is streaming now on Netflix.