“Methadone gave me my life back,” Ms. DiPierro, who declined to be interviewed, wrote in a sworn statement attached to the lawsuit. Without the treatment in prison, she added, she fears that upon her release, “I will lose control of my addiction and I will relapse, overdose and die.”

[Like the Science Times page on Facebook. | Sign up for the Science Times newsletter.]

The federal prison system has estimated that about 40 percent of its roughly 180,000 inmates have a substance use disorder. But while it uses methadone to detox new inmates who are dependent on opioids, it does not allow anti-craving medications as ongoing treatment except for pregnant women, who can take methadone, according to a spokesperson.

With overdose deaths from synthetic fentanyl continuing to rise, and newly released inmates at much higher risk because they lose their opioid tolerance while incarcerated, prisons and jails around the country face increasing pressure to offer anti-craving medications. But only Rhode Island and Vermont are offering state prisoners all three medications approved by the F.D.A. to treat opioid addiction: methadone, buprenorphine and naltrexone.

At the urging of the Trump administration, the prisons bureau recently started offering naltrexone to inmates who are about to be released to halfway houses. The spokesperson said naltrexone is being offered in 23 prisons in the Northeast and will eventually be expanded, but would not say how many inmates had received naltrexone injections so far.

Many in law enforcement favor naltrexone, marketed as Vivitrol, because unlike methadone and buprenorphine , it is not an opioid itself and is taken once a month instead of daily. But there is less evidence backing its effectiveness, and some studies have found people don’t stay on it as long.