Cryptocurrencies like bitcoin have long been seen as a risky investment, but in places like Venezuela, they can also be dangerous. Thousands of Venezuelans have turned to secretly mining the digital currency — which is closing in on a record high near $5,000 — for their economic survival, and for many that means risking jail time. Venezuela was once the richest country in South America, but it's now in crisis. It stands at the brink of civil war. Deadly protests paralyze city centers. It's the world's most indebted country, and its GDP has collapsed. Food and basic necessities are scarce, people are rationing toothpaste and toilet paper, and there are even reports of hungry Venezuelans killing flamingos and anteaters for food.

View of damages in a supermarket in Valencia, Carabobo State, on May 5, 2017, the day after anti-government protesters looted stores, set fire to cars and clashed with police, leaving at least five people injured and one dead. Ronaldo Schemidt | AFP | Getty Images

The country's future economic picture looks just as bleak. It already has the highest inflation rate on the planet. The International Monetary Fund expects prices in Venezuela to rise more than 1,100 percent this year. Venezuela's currency — the bolivar — is in free fall. Going against black market rates, it's lost 99.4 percent of its value since 2012. But bitcoin, ethereum and other cryptocurrencies are insulated from all that. They're fully decentralized so they're immune to what's happening in any one country — regardless of where they're mined. And that's why Venezuelans have turned to mining.

Venezuela's underground cryptocurrency miners In the cryptocurrency world, miners use computers to do the bookkeeping for digital transactions, verifying them and adding them to a public ledger. When someone mines, they earn digital currency as a payment for their efforts. It's been a lifeline for people like "Brother," a nickname used by an individual who lives just outside Caracas, who only agreed to speak to CNBC on condition of anonymity. The 29-year-old father initially got into mining because his $43 monthly salary from his government job wasn't enough to support the baby girl he and his wife had on the way. That's when he decided to start illegally using computers in his government office to mine. He has since quit his job and now mines using his own equipment from home. "Because of my daughter, I didn't think of it as a risk to what could happen to me in the company. I have to take the risk for her. I have to do this for her," says Brother.

"Brother" is based just outside Caracas and only agreed to speak to CNBC under anonymity. Source: CNBC

Brother's story is a familiar one. David Fernando Lopez has since fled the country, but he once ran a bitcoin mining farm out of Caracas for three years. He was 40-years-old and didn't have a job. Mining was the one thing that could take him out of poverty. "You can feed a family with one ether rig. It's a fact." Lopez says that a lot of people are doing this right now. "Andrea Perez" is among them. CNBC is using an assumed name for her to protect her identity. Andrea works three jobs, yet mining bitcoin represents roughly 80 percent of her income, or around $120 per month. "For me, bitcoin has represented the ability to be able to support and feed my daughter in a very volatile environment." With a drastic shortages of supplies, Lopez says the easiest way to get basic amenities is to use cryptocash on e-commerce site purse.io. He orders staples like soap, deodorant, and shampoo — then a courier from Miami will deliver the goods right to his office. Others use cryptocash to buy vital medicine, like insulin, from overseas.

You can feed a family with one ether rig. It's a fact. David Fernando López Former bitcoin farm operator

The process of mining itself isn't all that intuitive, so many have turned to online forums and YouTube tutorials to learn how to do it. Randy Brito runs an online forum called Bitcoin Venezuela that teaches people how to mine. Brito operates remotely out of Spain, having fled Venezuela with his family when he was 14. What started as a community of 10 users has ballooned to nearly 10,000 people. "People are barely making a living with their jobs there. Even if they're a professional, they are not able to work," Brito said. "So people are finding that mining is a way to make a predictable income for their families." Though it's a vital source of income for many, he says the danger of mining is becoming more acute by the day. "People who mine bitcoin or crypto with mining rigs, they're usually doing it underground," said Brito.

David Fernando Lopez spent three years running a bitcoin mining farm. Source: David Fernando López

Venezuela's crackdown on mining Mining cryptocurrency is completely legal in Venezuela, yet police have been arresting miners. It began with Valencia-based Joel Padron and Jose Perales. Local media reported both were arrested and detained for several months in 2016 on charges of energy theft and possession of contraband. The number of arrests and raids has steadily grown since then. When asked about why authorities were cracking down so hard on bitcoin miners, a detective from the national police (CICPC) told CNBC that in many of these cases, suspects were "exploiting resources without documentation."

Lopez ran his mining farm out of Caracas. Source: David Fernando López

However, some miners said the Venezuelan government views cryptocurrencies as a threat to the already weak bolivar and to its strict rules about capital flight. Government officials could not immediately be reached for comment. One Reddit post by a Venezuelan bitcoin miner claimed that, "miners are getting jailed and accused of terrorism, money laundering, computer crimes and many other crimes. It's getting crazy here and I really don't want to waste my life for money." "Miners are getting jailed and accused of terrorism, money laundering …" A year ago, "Tego Sanchez" spent his life savings on mining hardware and taught himself to mine. It now accounts for 80 percent of his income. At ethereum's peak price, he earned roughly $20 daily. But the 23-year-old says he lives in constant fear of being caught after seeing his friends arrested in raids. He says that's a big reason Venezuela's crypto community largely runs on secret groups and encrypted messaging apps like Telegram. That's also why he uses an assumed identity.

"Tego Sanchez" spent his life savings on mining hardware. Source: CNBC

"I haven't had any problems with national security forces because I don't talk about it. Not even my friends know what I do," he said. "My grandmother is the only person who knows because I live with her." "Mateo Patino" also taught himself to mine back when the economy went sideways in 2012. At the height of bitcoin's value, he raked in up to $600 monthly, roughly three times the wage he earned as a journalist. Patino says he was approached by the SEBIN, an acronym given to the country's intelligence service — the Servicio Bolivariano de Inteligencia Nacional. "They started to ask questions about why I was drawing so much power from my house. I actually turned off all my bitcoin miners, and I moved them to another secure location."

A friend of Lopez helped assemble his bitcoin mining farm back in 2013. Source: David Fernando López

This is one way authorities track down miners. Venezuela has heavily state subsidized electricity. That keeps the price low, which is a major incentive, because mining for cryptocurrencies takes an enormous amount of electrical power. However, it also means police monitor power consumption all across the country. Miners said when authorities see that somebody is using too much electricity, they go after them. That's why many arrests of miners are on charges of internet fraud and electricity theft. Earlier this year, four miners in Charallave were arrested for allegedly endangering the stability of the town's electrical service. Brother said he not only protects his online identity; he also conceals his electrical footprint. He has split his mining equipment across three different locations, and pays his neighbors to use their electricity so he can spread his devices across multiple power grids.

National electricity transmission grid of Venezuela Source: CNBC

But even using precautions, Patino said, mining for bitcoin, in particular, is a major gamble. "Mining bitcoin became something out of a spy movie, because miners were getting arrested on false charges," Patino said. "Many bitcoin miners are being prosecuted. Many, they're scared, they're paranoid." Lopez said he ultimately had to get out of the business entirely for his own safety. Though 99 percent of his net worth is still invested in bitcoin, Lopez said he now chooses to trade the cryptocurrency instead, a bystander as the danger of mining grows.

After getting out of the business of mining, Lopez ultimately fled Venezuela. Source: David Fernando López