The thing you don’t expect about playing baseball in prison is that everyone is extremely friendly.

The entire roster of convicted felons who suited up for the San Quentin Giants on Thursday seemed genuinely grateful for the opportunity to play against some weekend warriors from the outside: Welcoming us and thanking us for coming upon our arrival in the prison yard, stopping by the visitors’ dugout for pleasantries during the game, and thanking us again before we took off to a nearby brewery for a postgame meal.

I learned about the baseball program at California’s oldest prison through friends from my weekly pickup hardball game in Brooklyn, guys who played at the prison back when they lived in the Bay Area and participated in a similar sandlot affair. The Mission Baseball Club, as it’s known, plays multiple games a season against the San Quentin Giants, and welcomed me to join them last week for a 5-2 win, shortened to seven innings due to the permanent home team’s mandatory head count.

As the Giants warmed up on the all-dirt infield, about 150 inmates milled about the yard. Some sat in the shade in right field on the gravelly warning track that doubles as part of the prison’s walking track, in front of a home-run fence topped by razor wire. Others did dips and pull-ups in an exercise area that once held free weights before California prisons banned them decades ago. A grey-haired inmate faced the brick wall and honked out jazz standards on a tenor saxophone, riffing through a reedy rendition of On the Street Where You Live that echoed around the yard.

Baseball at the prison dates back nearly a century, and its current incarnation has been running continuously since 1994. Elliot Smith, a 72-year-old San Francisco real-estate lawyer, organizes the program. It’s open to every prisoner in San Quentin’s general population — excluding those on death row, in solitary confinement and in protective custody.

Prospective players try out in February, then get divided into two teams: The Giants and the A’s. Smith, who also manages the Giants, is a volunteer, as are all of the program’s coaches. All the equipment comes from donations, a situation complicated by San Quentin’s restrictions on what can be taken inside. The Giants’ uniforms, a long-ago gift from the San Francisco Giants, have been bleached by the sun from their original black to a sandy grey.

“There are a lot of hurdles,” Smith told USA TODAY Sports. “Security concerns, rules about equipment and how it’s brought in. Organizational issues, and problems with managing the team. You have a predominant base of murderers and lifers on the team, which is in a way good, because it adds stability: Guys who come back year to year know how it operates. But a lot of these guys have all sorts of issues with competition, with failure, with anger. Some of them are in prison for a reason.

“You have to deal with all these personalities, put a team together, and try to play as one team. It’s difficult at times. You have to have a lot of experience in it, and an understanding of what kind of pressures they may be feeling off the field that might be contributing to the problems you see on the field.”

Just before first pitch on Thursday, at some signal I entirely missed, every player on the Giants dropped to one knee and waited motionlessly for the go-ahead to resume baseball activity. The coordination gave it the appearance of a religious ceremony, but here the inmates kneeled only before a garbled voice buzzing out of the prison P.A. and San Quentin’s frequent but necessary efforts to maintain order.

My nerves hummed before my first at-bat, in part due to lingering anxiety from the extensive security protocols required for all prison visitors. Smith collected my information long ahead of time for background screenings, but visitors are welcome only at the prison’s discretion and Smith can never be certain that the players he brings in will make it past San Quentin’s front gate. Once they do, and after they acknowledge the prison policy that states it will not negotiate for a visitor’s safety in a hostage situation, they proceed through multiple checkpoints and inspections before the barred iron doors clink behind them and another set opens to allow entrance to the yard.

There’s no mistaking it: You’re in prison.

My first time up, I got out in front of a pitch and cued it off the end of the bat just over the pitcher’s mound, where it died on the dusty infield. I beat out a wild throw from the charging second baseman and wound up with a two-RBI infield hit thanks to some generous scoring from the inmates out in right field hand-operating a scoreboard that reads “SAN QUENTIN’S FIELD OF DREAMS.”

On first base, I reminded myself to stay back on the ball my next time up and watched for the pitcher’s pickoff move. Once the game begins, it’s just like any of the hundreds of baseball games you’ve played in before: Guys chatter in the dugouts, yell out support for their pitchers from the infield and call each other nicknames like “Slick” and “Sparky” and “Stretch.” A group of inmates in prison blues behind the backstop heckles hitters on both teams with “swing, batter!” and shout “I got it” on pop ups in front of the plate. Baseball stuff.

It was only on an ensuing ground ball to the shortstop that I remembered the setting, and opted not to slide in with my spikes up to break up the double play.

Inmates can forget where they are during games, too. That’s why most of them play.

“It’s an escape from the norm of prison: The controlled environment, feeling oppressed,” said Ke Lam, a 38-year-old who has spent his entire adult life behind bars after killing someone in a gang fight when he was 17. “This is a place where I can actually feel free.”

“Baseball has a funny way of equalizing things,” said Damon Cooke, a 50-year-old financial consultant and Giants first baseman who has spent 25 years in prison for attempted murder. “It’s just a normal setting.”

No one wants to be in prison. But if you have no choice, you could do way worse than San Quentin. Several of the players here spent years in California’s penal system jockeying to get to this facility, a process that typically requires good behavior, good luck, and an apparent dedication to rehabilitation through participation in prison programs — “programming,” as several players call it.

Thanks in part to its location in uber-wealthy Marin County, about 10 miles north of the Golden Gate Bridge to San Francisco, San Quentin offers opportunities inmates mostly cannot get elsewhere: Degree programs, vocational training, support groups, mentorship, and, among other things, the only prison hardball program in the world that welcomes outside players as opponents. Inmates appreciate this game as a rare chance to compete and converse and commiserate with people who aren’t in prison. That’s part of why everyone’s acting so nice.

No one winds up in San Quentin without some serious ugliness in their history, even if many of the players here have spent a lifetime repenting for whatever malicious act landed them here. But there’s real beauty in the baseball, as there always is everywhere: The Giants turned a pretty pair of double plays against us on Thursday and executed a perfect relay to throw out a runner trying to score. On Saturday, in a game against a men’s league team from Los Angeles, Giants players hooted and smiled as they won 10-7 on a three-run walk-off home run in the 10th inning.

“This is the time you’re not in prison,” said John Windham, a 45-year-old A’s player who has been in the penal system since he was found guilty of abetting a murder in 1989. “It helps you get out of your box. It’s a beautiful experience.

“It feels like I’m home. It feels like college, except without the women.”

Windham wants a green seedless grape, and you can’t get one here — apples and bananas, yes, and occasionally some watermelon, but never grapes. San Quentin is the eighth different facility in which he has been incarcerated. One of the prison’s best athletes by his own and most other accounts, Windham stars in multiple sports programs and recently played Octavius in the inmate production of Shakespeare’s Julius Caesar. He will face his fifth parole-board hearing next year, and dreams of someday having a refrigerator — not necessarily for what he can store inside, but for the feeling of getting up from the couch, opening up the fridge, taking stock of what’s inside and closing it again.

None of the inmates with whom I spoke claimed his innocence, and several made a point of noting that they recognize the need for prisons and understood that bad choices they made put them here. None appeared to be seeking pity or mercy, just normalcy, and ways to pass the time and prepare themselves for a return to society — should they get one.

Baseball offers all that: The San Quentin teams typically play twice a week from April to August, and they include players from all races interacting in ways not always common in other prisons, where inmates can be ostracized for interracial mingling. Michael Lane, the Giants’ 39-year-old scorekeeper who has served 11 years of his sentence for second-degree murder, told of working in a kitchen at another prison alongside inmates of another race, but never speaking to them for fear of repercussions from inmates of his same color.

“I love the teamwork, the camaraderie,” Lane said when asked about his role with the Giants. “It’s a blast, man: Being part of a team, getting to wear the uniform. And it’s a way to stay involved with a game I love.”

“It sort of socializes them a little bit more,” Smith said. “We have an integrated team in a prison system that’s not integrated. For a lot of guys, it’s the first time they mix with other races on any basis. It helps them deal with a lot of problems they’re going to have to deal with on the outside.”

None of that makes life at San Quentin easy. The Giants lost two of their best players to solitary confinement earlier this season, a concern that threatens the team’s roster as much as it has any club since the 1986 Mets. Some teammates seemed certain the players will ultimately be cleared of the drug-smuggling charges and return to the field, but due process doesn’t exactly work the same way when you’re already incarcerated.

And the playing conditions here are hardly ideal: The outfield lawn, once well maintained, has gone brown due to restrictions related to California’s drought, swallowing up fly balls into the monochromatic confluence of dead grass, dry infield, and the prison’s yellowed buildings. Pop-ups become disorderly when they sail up above the prison walls, swirling in the breezes gusting off the San Francisco Bay.

Lam got a couple of key hits and earned the win in relief on Saturday, in what he hopes will be his last time ever playing baseball in San Quentin. A sweet-swinging, switch-hitting model prisoner who even helped organize a prison breast-cancer walk, Lam looks forward to eating fresh seafood for the first time in 22 years. He has already been declared suitable for parole and expects to be released in November, if and when his case is approved by Gov. Jerry Brown — who has proved more willing than his predecessors to abide the suggestions of parole boards. The Mission team has invited Lam to join them once he’s out. But he’s got a lot he wants to do to make up for lost time, and to repay society for the mistake he made at age 17.

Lam’s exit from San Quentin seems likely, far more so than those of his teammates. Smith, in passing, noted that every inmate has a date or a month or a year in mind for when he will finally get paroled and enjoy or endure the trappings and challenges of life on the outside. Until then, they study. They pray. They recover. They read. They take coding classes; they give tours of the prison; they learn crafts, and instruments and the power of positive thinking. They play baseball.

And they owe so much of that to volunteers like Smith who operate the programs that allow prisoners to rehabilitate and ready themselves for the real world, and, maybe, to spend some tiny fraction of serving life actually enjoying life.

“You’re helping people that society has forgotten,” Smith said. “They’re sort of like thrown-away people: They stuff ’em in a warehouse and forget about them. They’re human beings and they have lives, and most of them are going to get out and be in society again. I’m in there to help them get through it.”

“We came from someplace,” said Windham. “We are brothers, sons, fathers, cousins, uncles, that made bad choices. But we are more than what we’ve done. I believe in redemption. I believe we can change.”