This abandoned prison in northern California is being transformed into a massive medical marijuana farm after the city of Coalinga agreed to sell it for $4.1 million.

Claremont Custody Center held more than 500 state inmates but has been vacant since its contract was terminated by the California Department of Corrections and Rehabilitations in 2011.

Now, after months of proposals and negotiations, the empty prison will soon be converted into a high-security factory where cannabis oil will be extracted from thousands of medical marijuana plants.

Claremont Custody Center, in Coalinga, California, held more than 500 state inmates at any given time

The former prison has been vacant since its contract was terminated by state officials in 2011

It will soon be converted into a high-security factory where cannabis oil will be extracted from pot plants

Coalinga's city council recently approved the sale of the building to Ocean Grown Extracts for $4.1 million

Ocean Grown Extracts is planning to begin operations inside the former prison by the end of the year

Earlier this month, Coalinga's mayor and councillors voted 4-1 to allow commercial marijuana farms inside city limits, and approved the sale of the former prison to Ocean Grown Extracts for a seven-figure sum.

With dozens of job losses and costly maintenance fees, the dormant prison has been a financial burden for Coalinga since its unexpected closure.

Before the sale city was carrying a debt of nearly $4 million after paying unemployment benefits and maintenance costs for nearly five years.

But the sale of the 77,000-square foot facility will immediately bring Coalinga's general fund into the black and create around 100 new jobs, the Fresno Bee reported.

The former prison's interior remains largely untouched, although it will be completely overhauled to make way for the cannabis oil production facility.

With dozens of job losses and costly maintenance fees, the prison had been a financial burden for Coalinga

The sale of the 77,000-square foot facility will bring Coalinga's general fund into the black and create 100 jobs

Coalinga was carrying a debt of nearly $4 million after paying unemployment benefits and maintenance costs

In addition to the prison closure, Coalinga has taken a financial hit from the downturn in the crude oil industry

Even though the recreational use of marijuana is illegal under federal law, it has been legal for medical purposes in California for a decade.

Casey Dalton, co-owner of Ocean Grown Extracts, said she hopes the business will be operating inside the former prison by the end of the year.

'We're thrilled to be able to offer 100 jobs and make safe medicine available for patients,' she told the Fresno Bee. 'We appreciate Coalinga taking a chance not only on us, but on the industry.'

Ocean Grown Extracts and any other companies that are permitted to grow medical marijuana within city limits must abide by strict rules.

All employees or contractors must pass background checks and receive work permits that are kept on file with the local police department.

Facilities must be gated, locked and closed to the public, and have 24-hour video surveillance that can be accessed by police.

Medical marijuana farms are not allowed to post signs, they must have odor control measures and every plant must be fitted with a tracking device.

The use of marijuana has been legal for medical purposes in California for a decade

Medical marijuana growers must abide by several strict rules set out by Coalinga's city council

All employees or contractors must pass background checks and receive work permits that are kept by police

Facilities must be gated, locked and closed to the public, and have 24-hour video surveillance systems