Image copyright Getty Images

For months, thousands of firefighters have been battling raging wildfires in the tinder-dry forests of drought-stricken California. Most are employees of the state's fire service, but more than a third are prisoners, who earn money and early release in return for doing an exhausting, dirty and dangerous job.

When painter Henry Cruz was sent to San Quentin prison three years ago, for a crime he doesn't want to talk about, he never thought he would spend part of his sentence fighting fires. But that's what he has been doing for the past 18 months.

"It gets scary sometimes, but at the same time, it makes me feel good. Being a firefighter is a privilege - it makes you feel like you are in civilisation.

"I like saving nature, and sometimes people," he says. "It makes me feel like a hero."

Image caption Henry Cruz is known as a 'swamper' because in his crew he is the fire captain's right-hand man

Being a firefighter is hard work, says 29-year-old inmate James Sharp, from Sacramento.

"You've got about 40lb (18.1kg) of gear on you - it's definitely hot, you are constantly sweating," he says.

"We work 24-hour shifts and the last fire I was on - the Rocky fire in Lake County, which burned about 69,000 acres and threatened homes - was on very steep terrain. We had to get flown in on a helicopter twice and hike 10 miles to get out at the end of the day. It was pretty intense, and went on for 32 days straight. I was very tired, worn out, drained."

Media playback is unsupported on your device Media caption Prisoners explain why they volunteered to be inmate firefighters

Cruz and Sharp are two of about 4,000 inmate firefighters in California.

The state - which suffers from some of the largest wildfires and some of the most overcrowded prisons - has been using prisoners to battle blazes since 1946.

All of the firefighters are volunteers - but not everyone who volunteers is accepted.

Inmates convicted of crimes categorised as "serious" or "violent" felonies are not eligible, says Bill Sessa, a spokesman for the state's department of corrections and rehabilitation (CDCR). That rules out those convicted of murder, kidnap, rape and other sex crimes, violent assault, and - unsurprisingly - arson.

Prisoners must also have a good behaviour record to be accepted, and can only apply if they are held in a medium-security or low-security institution.

There are incentives to sign up. Inmate firefighters earn $2 a day, plus $1 an hour when they are out on a fire - which compares to a going rate of about 10-35 cents an hour for a normal paid job in prison.

It can also accelerate a prisoner's release. While most California inmates are entitled to "day for day" credits for good behaviour, firefighters earn two days off their sentence every day they are on a fire.

Image caption Bryan Earnhart (left) and James Sharp (right) say firefighting has altered their outlook

Bit by bit these benefits add up, says 27-year-old inmate firefighter Bryan Earnhart.

"I've got about six months knocked off my sentence. The pay might not sound much, but [as] the last fire went on, we made about $800," he says.

But like Henry Cruz, he doesn't just do it for the money.

"From being locked up, you can't beat this experience. I've got to fly in helicopters... I've learned the trades of running a saw, 'cutting a line'. I've been in and out of prison for five years, but this is the first time I actually want to live the right way when I get out," he says.

Image copyright Getty Images Image caption An inmate checks for hotspots at a fire known as the Jerusalem fire, in northern California

Inmate firefighters don't actually spray water from fire hoses or helicopters. Those jobs are done by civilian firefighters with California's department of forestry and fire protection (Cal Fire).

But the crews of between 12 and 14 inmates, supervised by a fire captain, often have to work right on the edge of fires, up against flames more than 100 feet tall. They use hand tools, such as chainsaws, axes and rakes, to contain the fire by clearing the vegetation around it, and patrolling areas after a fire is put out to ensure it does not flare up again.

"Their job is extremely dangerous," says Sessa. "There are a handful of major injuries a year - when inmates are hit on the head by a falling tree top, flying debris or break an arm," he says. He cannot remember any inmate deaths, though, in the 10 years he has worked for the CDCR.

Overall, inmates do more than three million hours of emergency response work and save the state roughly $80m every year, CDCR estimates.

"The inmates do a difficult job in dirty, dense terrain," says Cal Fire's Lynette Round. "They are critical to containing fires."

Image caption Glen Oak is surrounded by beautiful mountains and wildlife

When the inmates aren't firefighting, they live in 43 camps sprinkled across the state, often in the middle of the forest or mountains, carrying out fire prevention work such as tree-thinning or community work like removing roadside litter.

The camps are guarded by prison staff, but often have no walls or electrified fence. Sometimes there isn't a fence at all.

Food is better because of the extra calories firefighters need, and there are facilities such as a weights room, pool table and hobby area.

Image copyright AP Image caption California has 225 women inmate firefighters (picture: Yosemite, 2008)

Sgt Brian Sloat, who supervises firefighting inmates at California's biggest conservation camp, Glen Oak, says the camp system is the most successful rehabilitation programme the state offers, and generally inmates play by the rules.

But he says staff have to be "hyper vigilant" about contraband such as drugs, alcohol and weapons, and escape attempts do occur.

"If an inmate is violent or threatens violence, everything changes. Handcuffs, leg irons and waist chains come out, and it becomes prison really fast. They go straight back to an institution," he says.

Image caption Signs remind inmates that a camp is still a prison

California isn't the only state that has inmate firefighters. Last month, Washington state made headlines when an inmate escaped from a work camp and wounded himself with a gun during a standoff with police.

Inmate firefighters from Nevada have been drafted in to reinforce crews in California, which is battling more fires than usual after a four-year drought. They also exist in Wyoming and Arizona - but California's programme is by far the biggest.

David Ball, an assistant professor in criminal justice at the Santa Clara University School of Law, says inmate firefighters are part of a long history of prison labour in the US, pointing out that when Congress passed the 13th Amendment in 1865, which abolished slavery and involuntary servitude, it made a specific exclusion for penal servitude by including the phrase "except as a punishment for crime".

Some people see the use of inmates in this way as exploitative, he says, but while prisoners are not in a good bargaining position, they do volunteer.

Do prisoners feel exploited or bribed into putting their lives on the line?

Traveon, 22, says most of his crew would rather be out on a fire than back behind bars.

"Fire captains are very experienced and wouldn't put us in a situation they don't feel comfortable with. Yes it's hard, but people are grateful. I'm not saying this is an adventure, but it's a life experience, and hopefully when I do get my freedom, it will give me a better chance of getting a job," he says.

Earnhart agrees it's no holiday.

"I wouldn't say we are slaves, but I've never worked this hard in my life," he says.

But he credits the programme with giving him a new sense of purpose.

"People know we are inmate firefighters because we are in orange, but they cheer you on because you are out there protecting people's homes. They put up 'thank you' banners and bring apple pie - it's such a good feeling," he says.

"I get an adrenalin rush every time the sirens go off and we go out on fires," he says.

In two months he will be released, and is thinking of applying to become a hotshot - an elite team of firefighters specially trained to deal with wildfires.

Cal Fire says it's possible for inmate firefighters to make the transition, but cannot say how many have done it.

Cruz is also considering swapping his paint brush for a hose.

"I feel like this has given me a second chance," he says.

Subscribe to the BBC News Magazine's email newsletter to get articles sent to your inbox.