In the summer of 2017,  just weeks before Ben Stiller was scheduled to start filming Showtime’s limited series “Escape at Dannemora,” the director had a serious dilemma: He had nowhere to shoot the prison scenes.

For months, Stiller, who also serves as executive producer, and the “Dannemora” production team had been trying to gain access to New York’s largest maximum-security prison — the Clinton Correctional Facility in Dannemora. Stiller wanted to shoot within and around the facility, which holds approximately 2,500 male inmates, but the organization that manages and operates the state’s prisons, the Department of Corrections and Community Supervision, wasn’t biting.

But Stiller wasn’t taking no for an answer. The director was adamant about filming on the grounds and for good reason: The majority of “Dannemora,” the true story of Richard Matt and David Sweat’s prison break that was being adapted into an eight-part limited series, took place within the walls of the Clinton Correctional Facility. The prison, like Matt and Sweat, was an essential character in the series.

The story of the men’s escape in the summer of 2015 reads like it was ripped from a Hollywood movie script. Matt, who was serving 25 years to life for dismembering a man, and Sweat, who was serving a life sentence without the possibility of parole for killing a sheriff’s deputy, were the first inmates to escape from the maximum-security prison in more than 100 years. The duo’s elaborate plan, which involved squeezing through a catwalk and crawling through dimly lit underground tunnels and pipes, was aided by a married prison employee named Joyce Tilly Mitchell with whom both had been sexually entangled. Their escape spawned a massive, costly three-week manhunt. Ultimately Matt was shot and killed by authorities, while Sweat was captured and returned to prison. A sentence of three to seven years was added to his original life term, and he was ordered to pay $79,841 in restitution. Mitchell was sentenced to up to seven years for her part in the escape, which included smuggling hacksaw blades and other tools to the two inmates via frozen hamburgers.

Those tawdry details explain why “Ray Donovan” writing team Brett Johnson and Michael Tolkin started working on a script about the incident even before Matt and Sweat were respectively killed and captured.

The first time he got the directing offer for “Dannemora,” Stiller passed due to lack of facts in the script. “I felt like I didn’t know enough about the reality of what happened, and I didn’t want to do something that was based on speculation,” Stiller tells Variety during filming at an abandoned Brooklyn warehouse that has been transformed into Clinton Correctional’s tailor shop. “I was interested in what really happened, but at the time, [Johnson and Tolkin] didn’t have that much actual information.”

Then in June 2016, the New York State Office of the Inspector General released a 150-page report detailing the specifics of the escape, which the writers worked into the script, and Stiller agreed to sign on. Patricia Arquette, who plays Mitchell, was the first to commit to “Dannemora.” Soon after, Benicio Del Toro and Paul Dano boarded the project to play Matt and Sweat respectively.

Stiller’s devotion to capturing the story accurately drove the director on a quest to shoot on the grounds of Clinton Correctional. He wanted access to the North Yard, where the inmates devised their plot, as well as the outskirts of the facility, which is surrounded by a 30-foot concrete wall and armed guard towers. But without official consent, filming in and even around the prison, including the manhole just outside it that Matt and Sweat popped out of on June 5, 2015, would be impossible. “The reality of shooting outside Clinton was that if we didn’t have the cooperation of New York State Department of Corrections, we would basically just be out there on our own,” Stiller says, “and anything could really happen if they weren’t wanting us to be there.”

With the start of principal photography looming, Stiller and his team tried to come up with an alternative approach. To re-create the multi-mile border wall, he and executive producer Bill Carraro considered using visual effects, but gave up on the idea. Computer effects wouldn’t ring true to the series’ “very real” tone.

As for re-creating the surreal North Yard, Stiller knew it would be hard to find another location because nothing like it exists. With its spectacular views of the Adirondacks, the North Yard is the size of two or three football fields. (For safety and security reasons, officials won’t release the actual dimensions.) Hovering over the yard’s expansive flatland is a hill that is divided into 163 courts, or little slices of turf. Each court has wooden furniture and contains sheet metal stoves for grilling. During the warmer months, inmates can garden within the courts. “It’s a place you look at and go, ‘I can’t believe this actually exists,’” Stiller explains. “It is its own environment or ecosystem that is considered the most dangerous place in the prison.”

Stiller and Carraro debated filming instead at a prison facility in Pennsylvania, but as with using visual effects to create the border wall, they decided it just wouldn’t work. “The North Yard was just impossible to re-create,” Stiller says. “It represented the strange reality of living in this place as a prisoner. Being out there in the yard looking out across at the Adirondacks, it’s almost like haunting freedom.”

But officials weren’t interested in how the North Yard would serve the narrative — especially a story that highlights an embarrassing piece of history for the facility and its workers. “The Department of Corrections is in the business of minding the prison and not necessarily working with filmmakers to tell a story,” says Carraro.

While DOCCS would not say why it originally rejected “Dannemora’s” request to film in the prison, it explained in a statement to Variety that “when contacted by a production company requesting permission to film inside and/or outside an open correctional facility, a thorough security evaluation is conducted and the department and the filmmakers engage in an ongoing dialogue to discuss all safety concerns.”

Carraro said there was also concern from Dannemora locals, many of whom work at Clinton Correctional, about what kind of story Stiller and his team was going to tell.

“The escape was a blemish for DOCCS,” says Carraro. “But it happened because of a  couple of bad apples. There is still a lot of pride in what takes place in the organization that helps monitor the prison, and we felt the best way to tell their story and represent what they do was to have some access to the actual prison in order to give people an idea of what it’s like from both the prisoners’ and corrections officers’ point of view.”

Desperate to find a solution, Stiller thought that if he could explain to someone within DOCCS that he just wanted to tell a nuanced story of what really happened, he might be able to gain entry. And that’s when he remembered that he knew a guy — a guy in New York City Mayor Bill de Blasio’s office. And that guy knew someone in Gov. Andrew Cuomo’s office. A couple of days later, Stiller was sitting across from Cuomo explaining why he needed to film at the prison. (Cuomo is played in “Dannemora” by “Sopranos” alum Michael Imperioli.)

“I told the governor the situation, and he said, ‘Well, looks like you guys have to shoot at Clinton,’” recalls Stiller. “When he said that, I had this moment where I’m sitting there with him and I’m just thinking of the 200 people back in the production office and how their lives are all going to change because we were finally going to have access to this place.”

Cuomo’s reasoning for allowing the project access came down to economics, he explains. Since 2011 the state’s $420 million tax credit program has, according to New York state, generated more than $22 billion in spending and better than 1.3 million hires. While production in New York City is at an all-time high, upstate production could use a boost. “[Stiller] wanted to shoot it at Dannemora because it happened at Dannemora,” Cuomo says. “From our point of view, doing a movie in the North Country is great. It brings people to the North Country. From an economic point of view, purely selfishly, it was great for the economy.”

The “Dannemora” production spent 10 days shooting at parking lots and along the exterior of the facility and was given access to the manhole from which Matt and Sweat climbed out. The production also spent two days filming in the North Yard — a first for the prison.

To ensure the production’s safety, both the production and the inmates were on lockdown. Explains DOCCS, “In the interest of security, the cast and crew was not permitted to repeatedly enter and leave the facility on the days of filming in the yard.” Instead cast and crew were processed in and escorted to the recreational yard at the beginning of the shooting day and processed and escorted out of the facility following the completion of production.

On filming in the North Yard, Dano says it had a direct impact on his performance. “The second you step in [the prison], your body changes,” he says. “The air. The chill. The smell. The sound. They enter you without asking. Being in the yard looking out at the mountains — you want out immediately.”

Providing that hostile, realistic setting for his actors is something Stiller doesn’t regret fighting hard for.

“There were people in Dannemora who were concerned that we would be portraying this prison as a place that was run by people who were inept,” he says. “But by allowing us access to the prison and the people, [Cuomo] allowed us to capture more of the gray area of what goes on in the prison.”