A prisoner at HMP Durham "lunged" at a female prison officer with a razor blade.
Jonathan Adams "rushed" at the prison guard after smashing a plastic disposable razor and arming himself with the blade on January 16, 2020.
Durham Crown Court heard the officer went to the 24-year-old's cell over "concerns for his safety".
Read more: Go here for the latest reports and live updates from North East courts
Adams was serving a 16-week sentence at the category B men's prison over threatening behaviour.
He appeared at Durham Crown Court on Thursday to be sentenced for attempted wounding with intent.
He pleaded guilty to the charge on the day his trial was due to begin.
The court was told the prison officer was on duty at the prison's E wing when she saw Adams' cell observation panel had been blocked.
Due to concerns over his safety, the officer opened his cell door to speak to him.
"The defendant was standing in the middle of his cell, topless, wearing jogging bottoms", the court heard.
Adams did not say anything to the officer, but instead picked up a disposable razor before throwing it on the floor and "stamping" on it to break the plastic and "expose the razor".
Believing he would harm himself, the officer tried to speak with him before he picked up the blade and "rushed" at her.
The court was told Adams "lunged" towards her face.
Fortunately, another prison officer had arrived and managed to intervene and "struck" Adams with a baton and took him to the floor.
The officer "continued to deliver strikes as [Adams] continued to advance towards them".
Adams was restrained and later taken to hospital to be treated for injuries.
In interview, he said he could not remember the incident due to a "mental health episode", but denied intending to do harm to the officer.
In mitigation, Paul Reid, said: "The person who he was is not that person he is today."
He said Adams had mental health difficulties and had "maintained to stay off drugs".
"Probation say they are able to deal with him in the community", he added, saying Adams also had an offer of employment.
Sentencing Adams, of Portchester Square, Sunderland, Judge Ray Singh, said it was an "extremely serious offence".
"A female prison officer went to your cell and was concerned for your safety", he said.
"Rather than appreciating her concerns, you decided to pick up a disposable razor and smashed it, exposing the blade.
"Almost immediately, you rushed towards her, and lunged at her directly towards her face with that razor blade."
Adams was jailed for 40 months.
For daily news from the North East's courts direct to your inbox, go here to sign up to our free court newsletter