It’s called “the prison within a prison,” and anyone who watches a recently aired “Frontline” documentary filmed in the Maine State Prison’s solitary confinement unit can see why. The setting depicted in “Solitary Nation” is grim. Responding to prolonged isolation — 23 hours a day in their cells, with an hour a day outside in individual exercise pens — inmates yell, slash their wrists, flood their cells, push feces under the cell doors and slam their fists into walls.

So why has Maine been heralded nationally as a leader in the reform of solitary confinement? Because the Maine Department of Corrections has committed itself to reducing the use of segregation and made substantial improvements to its solitary-confinement policies. “Solitary Nation” documents this progress in a program that should be seen by everyone who cares whether inmates will be able to function in society when they leave prison — which should be all of us.

Keeping prisoners in isolation has been shown to cause depression, hallucinations, panic attacks, diminished impulse control and hypersensitivity to external stimuli, such as noise and light. Once out of solitary, moreover, inmates experience extreme anxiety at the thought of interacting with other people.

With this in mind, when Joseph Ponte came on board as Maine corrections commissioner three years ago, he began adopting reforms recommended in a government study. The prison must examine whether an inmate’s disruptive behavior can be addressed by less punitive measures than sending him to solitary, such as taking away the prisoner’s commissary privileges. The prison warden must sign off on the transfer to solitary for punishment. The corrections commissioner must approve any proposal to keep an inmate in solitary for more than 72 hours.

The result: The population of the segregation unit has been cut in half since 2011, from more than 100 to between 40 and 50. The average length of stay has been 30 to 40 days, “which is pretty good nationally. A lot of the bigger states that you hear, it’s measured in years,” Ponte told “Frontline.” As well, self-mutilation among segregated inmates has declined.

Opponents of solitary-confinement reform say that sending fewer inmates to solitary raises the risk of assaults on corrections officers. Indeed, the union for Maine’s prison guards welcomed the announcement last month that Ponte would be leaving to run the New York City jail system. Relaxing punitive policies increases the chance of violence, according to the union, which points to, among other incidents, a fatal inmate-on-inmate stabbing on Feb. 28.

But the inmate charged in the slaying, Richard Stahursky, is no argument for the use of segregation. Sent to the Maine State Prison in 2002, Stahursky had spent “substantial” time in solitary before reforms were implemented, said a prisoner advocate, and it didn’t help him. In fact, the lack of access to mental health services in the isolation unit prior to Ponte’s arrival aggravated Stahursky’s already tenuous emotional state and made it more likely that he would act out, the advocate said.

The killing committed by Stahursky is heinous, but neither it nor any other acts of violence behind prison walls should be allowed to derail reforms to the use of solitary confinement. The fact is that most prisoners eventually will be released. Ensuring that they’re equipped to handle public life when they hit the streets is the best way to protect community safety and pay respect to our common humanity.