Emily Lindley’s stash of marijuana is going to be very, very secure.

Lindley, a neurobiologist, is about to begin the first study ever to directly compare cannabis with an opioid painkiller (in this case, oxycodone) for treating people with chronic pain. She got a grant for this research two years ago, but it has taken that much time to meet all the requirements for working with a drug the federal government still considers highly dangerous.

Before it’s given to patients, the marijuana will be kept inside steel narcotics lockers bolted to the wall in a room with surveillance cameras and a combination keypad on the door. Each locker has tamper-proof hinges and requires two keys—each held by a different person. If someone puts the wrong key in one of the locks, it will become inoperable and have to be drilled out.

All this is necessary to comply with rules imposed by the Drug Enforcement Agency to make sure drugs meant for research don’t end up on the street, says Heike Newman, a senior regulatory manager at the University of Colorado’s Anschutz Medical Campus, where Lindley’s study will take place. Newman’s job is to help researchers with the paperwork they need to file with various government agencies to get approval for their studies. She says the lockers and renovations to the storage room cost the university about $15,000.

Just off campus, anyone 21 or older can walk into a dispensary and buy up to an ounce of marijuana, no questions asked. Under Colorado law, marijuana is legal for recreational as well as medical use. “I drive by a dispensary every time I come to work,” Newman says.

The current status of medical marijuana research is rife with irony. As states have liberalized marijuana laws, they’ve created new opportunities: Lindley’s grant is part of $9 million Colorado awarded for medical research in 2014, using tax money from marijuana sales. But since pot remains illegal at the federal level, researchers have to jump through regulatory hoops—lots of them—to do legitimate research.

Meanwhile, millions of people are experimenting on themselves in the states that have legalized marijuana for recreational or medical use. After this week’s election, 28 states (plus the District of Columbia) now permit some form of pot consumption.

The question of whether marijuana can help treat chronic pain is important enough on its own, but Lindley’s study takes on extra significance in the context of the ongoing epidemic of opioid abuse. According to the Centers for Disease Control and Prevention, since 2010 more than 14,000 people have been dying annually from overdosing on these prescription painkillers.

Physicians have commented for more than a century on the potential for cannabis to substitute for opioid drugs, and several recent studies seem to bolster this hypothesis. Researchers examining public-health records have found evidence that painkiller prescriptions, opioid abuse, and overdose deaths has declined in medical marijuana states.

The idea has not been tested with rigorous clinical trials, however. Such trials are expensive, and they’re normally paid for by a pharmaceutical company hoping to bring a new drug to market. Because a plant that exists and reproduces in nature can’t be patented, cannabis offers few opportunities for patents (and thus profits), which makes it look like a loser to most companies.

Lindley says her study wasn’t conceived with the opioid epidemic in mind, and she’s careful to note that no single study will be enough to settle the issue of whether marijuana could reduce the need for opioid drugs and keep people off a path that can lead to misuse, abuse—and worse. But it could offer some clues.

Lindley’s plan is to enroll 50 patients with chronic back and neck pain. While “these patients are large consumers of opioids,” she says, opioid painkillers aren’t very effective for many of them, especially over the long term. The idea to investigate cannabis came from a survey conducted several years ago with patients at the University of Colorado Hospital’s Spine Center. At the time—and this was before Colorado legalized recreational marijuana, in 2012—nearly a fifth of the patients reported self-treating with pot. Of those, more than three-quarters said it provided as much or more relief as their opioid pain drugs. It felt like a lead worth following up on with a carefully controlled clinical study.

Lindley’s patients will visit the university three times to receive either marijuana, oxycodone, or a placebo before undergoing a battery of tests to assess their pain and look for side effects.

Getting DEA approval for the study took about six months from start to finish, says Newman, the regulatory manager—not including the time spent on renovations, which the university knew they would have to do before they even tried to get DEA approval. There was a ton of paperwork and a minor snag when the university put forth the name of a pharmacist to hold the DEA license—and be the person ultimately responsible for safeguarding the marijuana—without realizing the agency would only grant the license to a physician.

There was also a site visit by field officers from the local DEA office in Denver, who inspected the storage room and went over the rules for handling the drugs. They collected personal information and ran criminal background checks on everyone who’d have access to them. The field officers seemed genuinely interested and enthusiastic about the research, Newman says. But perhaps also slightly out of their element—the DEA is better known for cracking down on drug trafficking than for regulating research.

This summer, around the same time the DEA was reviewing the application for Lindley’s study, the agency was also considering two petitions to remove marijuana from its Schedule I listing of drugs “with no currently accepted medical use and a high potential for abuse,” which also includes heroin, LSD, and bath salts. Taking cannabis off that list would loosen some of the restrictions for researchers—like the requirement for narcotics lockers. But the DEA decided not to relist it after a scientific review by the Food and Drug Administration concluded that the evidence of medical benefits didn’t meet their standards.

Medical marijuana researchers were disappointed, if not entirely surprised by the decision, given the relative lack of research. Some noted yet another irony:

The restrictions imposed by the DEA make it more difficult to collect the kind of evidence that would convince the DEA to loosen their restrictions.

To be fair, satisfying the DEA isn’t the only hurdle marijuana researchers face. They must apply to the National Institute on Drug Abuse for access to marijuana grown at a government-run farm at the University of Mississippi, the only product they’re currently allowed to use (though the DEA announced this summer that it plans to allow additional growers to supply pot for research). They must file an “investigational new drug” application with the FDA. And as with all experiments involving human subjects, their studies have to be approved by an ethical review board at their institution.

Even that might not be the end of it. In Lindley’s case, the university spent $40,000 upgrading the ventilation system in the room where the patients will receive marijuana, to comply with its own occupational and environmental health policies. And the patients won’t even be smoking it—they’ll be inhaling vaporized cannabis.

All that’s been taken care of, finally, and Lindley is eager to get on with her study. She hopes to enroll her first patients by the end of the month. In Colorado and other medical marijuana states, a huge, unsupervised experiment is already underway. Given that so many people are already self-treating with marijuana, Lindley says, it’s important to know whether there are actually therapeutic effects. “I’m not a proponent one way or another,” she says. “I think we need to do the research.”