Picture this: You must leave your rundown home. You scour rentals all over Oakland, but with four kids and monthly rents teetering around $2,500, you're about out of luck. You consider leaving the Bay Area for a more affordable inland region, but you and your partner's jobs are here; plus, the kids are in school.

Facing this predicament about two years ago, Christine and Emilio Hernandez got creative. They stopped sleuthing Zillow and Craigslist for homes, and started eyeing the vacant properties around them.

In October 2015, they snuck through a chainlink fence and into a three-bedroom house in Fruitvale. Most of the appliances had been torn out of the home – a former drug and prostitution den – and fire scars stained the walls and floors.

Christine, Emilio and their four children moved in. They became squatters.

Bryan Schatz told the story of the Hernandez family in the March-April issue of Mother Jones. Schatz found the family was not alone in its unique living situation; dozens of other people on the brink of homelessness live in the Bay Area by "squatting" – occupying land or buildings that you do not own without asking permission.

Squatting is one way to keep a roof over one's head in a region where median home values are over $1 million and affordable housing sparse. Alameda County's most recent homeless count found 5,629 are living unhoused – a 39 percent increase from 2015. Nearly 70 percent of these individuals are unsheltered, and 82 percent said they had lived in the county before becoming homeless.

READ ALSO: The Bay Area's long road to ending homelessness

The Bay Area's dire housing and homelessness crises inspired organizations like Homes Not Jails (HNJ), an organization formed in 1992 that seeks to house the homeless by helping them find and utilize vacant buildings.

"Since the government has been slow to act to utilize vacant buildings for housing, and people need housing now, Homes Not Jails simultaneously opens up vacant buildings and helps people who are homeless move in," a statement on the HNJ website says.

The organization claims to have opened hundreds of squats in its 26 years. Many of the squats have lasted for years, and some squatters eventually retained legal ownership of their homes through a process called adverse possession.

To claim adverse possession of a property, California law requires residents to have lived there for five years and to have paid five years of taxes. Then, one must wade through a complicated tangle of bureaucracy. That includes providing proof of "open and notorious" possession, meaning the squatter's presence was not hidden and the landlord could have reasonably learned about it.

It's an onerous, time-consuming process, but it's been done before.

READ ALSO: Bay Area residents who live in vans not to travel, but to contend with housing costs

Steven DeCaprio, 45, first broke into the West Oakland bungalow he now owns 15 years ago. The place was a mess, charred by fire and strewn with dead animals. He learned the owner of the place had died in 1982, and no one had stepped up to claim the house since. He and his friends moved in.

Speaking with Schatz, DeCaprio described the early iteration of the space as "Wild West meets cyberpunk."

DeCaprio eventually gained title to the home. He founded an organization called Land Action to help other squatters learn and defend their rights.

But homes obtained by adverse possession aren't exactly free. Through years of squatting around the East Bay, police kicked DeCaprio out multiple times.

He told KALW in 2014: "You know they'd board it up, and then I'd come back with, like, a hammer. And then they welded the storm door shut with, with an arc welder, and then I came back with a can of WD-40 and a Dremel with a diamond blade. And that's when they, that's when they finally were like 'Enough's enough, you're going to jail.'"

In 2016 he faced 8 1/2 years in jail and $89,000 in fines for felony conspiracy charges after assisting two Oakland squatters in 2015. The charges were dropped in 2017.

In the midst of his legal battles, DeCaprio continued running Land Action and studying to become a lawyer. He passed the California bar exam, but the state refused to issue a law license on moral grounds, citing an earlier misdemeanor trespass charge. DeCaprio has filed an appeal, according to the Mother Jones story.

Stories like DeCaprio's have played out across the Bay Area over the years, to varying degrees of success. In 2015 James Crombie, a former Marin County trader, was indicted by a Maryland grand jury on fraud and squatting charges after he and his family took up residence in a $1 million Bethesda home. The charges were later dropped.

Later that year, San Francisco police arrested a man who was squatting in a multimillion dollar Presidio Heights home containing hundreds of thousands of dollars worth of artwork, $300,000 of which the squatter had sold off. He was booked on 10 counts of burglary.

The Bay Area has a storied history of squatting, stretching at least as far back as the 1880s with the founding of the short-lived Mooneysville on Ocean Beach. The Mooneyville squatters seized prime oceanfront property under the justification that Park and Ocean Railroad had done the same, by unscrupulously grabbing federal lands. The miscreants set up a ragtag community of shanties, tents and shacks, in which they lived and hocked coffee, doughnuts and whiskey.

The carousal didn't last long; authorities broke it up within weeks of its inception.

READ ALSO: Bay Area adults forced to move back with parents

Less than a century later, the beatniks and hippies came to San Francisco, finding refuge in public parks and abandoned Haight-Ashbury Victorians. Some of the communities they founded have held fast, inculiding the Gates Cooperative in Sausalito. Like Mooneysville, this cohort of squatters lives by the sea, or in the case of this houseboat co-op, on the sea.

Founded in the 1950s and 1960s, Gates Co-Op went legit in 2014 with the support of the city and county. The houseboats were dismantled and renovated and, most importantly, converted from illegal squats to federally funded low-income housing.

Many squatters' stories do not have such happy endings. As for the Hernandez family, their story remains ongoing, how it will end, uncertain.

Christine and Emilio returned to their home one day to find their front door busted, the locks changed and their house pillaged, Schatz writes. The floor was flooded with flyers from M&M Mortgage. They read: "This property was found to be vacant and/or unsecured. It has been secured against entry by unauthorized persons to prevent possible damage."

The house, which the Hernandez family spent two years cleaning, fixing and occupying, was eventually put up for auction. It was sold for 1 cent over the opening price to a single bidder with plans to flip the property.

The median sale price for a home in Fruitvale in 2016 was $217,000, according to real estate site Trulia. In 2000, it was $97,000. The lone Fruitvale homes listed on Zillow at time of writing are priced at $599,000 and $749,000. A 2017 Zillow analysis named the neighborhood one of the five hottest Bay Area neighborhoods for home appreciation. The report projected home values to increase by 7.4 percent in the following year.

READ ALSO: Houses in SF sell nearly twice as fast as rest of nation

Shortly after the sale of their home, the Hernandez Family received an eviction notice. After they filed a motion to quash the notice, claiming it was not properly served, a judge ruled the eviction proceedings must start over.

Christine Hernandez already has a Plan B. She's eyeing a damaged, unoccupied home with a hole in the roof and debris in the yard.

"A person recently inherited the house," she told Schatz. "I want to reach out to that person and say, 'We're happy to completely clean your house. We'll paint it. We'll fix your roof. We'll take care of any business that needs to be taken care of, in exchange for you allowing us to live there for some agreed upon period of time.'"

Michelle Robertson is an SFGATE staff writer. Email her at mrobertson@sfchronicle.com or find her on Twitter at @mrobertsonsf.