Mr. Molina had never held a job before he was convicted in June. His brother works at a Starbucks on the Lower East Side and Mr. Molina figured the barista class would at least give him something to put on his résumé when he is scheduled to be released this month. “I didn’t have nothing, no experience,” Mr. Molina said. “So it was just going to be go back out there and do what I do, but this opens up other things.”

Mr. Hirsch, the barista trainer in Ohio, recently testified at the parole hearing of Gabriel Artis, 48, who was released from prison this year and now holds two steady jobs in Columbus, delivering furniture and driving a shuttle bus. Mr. Artis said the barista program gave him the skills to find these higher-paying jobs. “I’d been locked up for 23 and a half years. I needed to make sure my social skills were up to par,” he told me. “I drop off furniture to people’s homes so I need to be sociable and nice.”

The Ohio program reflects a wider trend in the criminal justice system, often funded by nonprofit donations, to update workplace training. In addition to classes like Foundations of Barista Skills and Intermediate Coffee Roasting, California state prisons also teach prisoners commercial diving and underwater welding and accredited classes in Autodesk software programs, which are used in construction and engineering. Younger inmates at San Quentin State Prison can learn how to code.

The goal is to pair a prisoner with potential work that takes advantage of their strengths. “Let’s say they’re in for selling drugs, then this is someone who has experience running a business and accounting,” said Dionne Barnes-Proby, a social policy researcher at Rand. “Yes, it’s illicit activity, but how can it be leveraged into something legal?”

The prison system started to see opportunity in coffee about five years ago after Starbucks endorsed “ban the box,” a movement to abolish the box on job applications that asks whether a candidate has a criminal history. The country’s 35,000 coffee shops employ 1.7 million people, according to the National Coffee Association. Starbucks, with its more than 15,000 stores in the United States, is by far the largest employer.

The coffee chain had become known for being relatively friendly to job applicants with criminal records. Starbucks doesn’t inquire about criminal history on an initial job application and won’t run background checks until after making a conditional offer of employment. “None of this is charity,” the company’s founder, Howard Schultz, wrote in a 2015 letter to Senator Cory Booker of New Jersey, a vocal supporter of ban the box. “We are simply giving people an opportunity — sometimes a second one — to prove themselves while helping to grow our company.”

Then, in 2017, Xavier McElrath-Bey, a senior adviser at the Campaign for the Fair Sentencing of Youth, spoke at the Starbucks shareholder meeting. He shared his story of being hired as a barista at a Starbucks on Chicago’s South Side after spending 13 years in Illinois state correctional facilities.