The version of the coronavirus that surfaced in Britain late last year was shocking for many reasons. It came just as vaccines had offered a glimpse of the end of the pandemic, threatening to dash those hopes. It was far more contagious than earlier variants, leading to a swift increase in hospitalizations. And perhaps most surprising to scientists: It had amassed a large constellation of mutations seemingly overnight.

A coronavirus typically gains mutations on a slow-but-steady pace of about two per month. But this variant, called B.1.1.7, had acquired 23 mutations that were not on the virus first identified in China. And 17 of those had developed all at once, sometime after it diverged from its most recent ancestor.

Experts said there is only one good hypothesis for how this happened: At some point the virus must have infected someone with a weak immune system, allowing it to adapt and evolve for months inside the person’s body before being transmitted to others. “It appears to be the most likely explanation,” said Dr. Ravindra Gupta, a virus expert at the University of Cambridge.

If true, the idea has implications for vaccination programs, particularly in countries that have not yet begun to immunize their populations. People with compromised immune systems — such as cancer patients — should be among the first to be vaccinated, said Dr. Adam Lauring, a virus expert and infectious disease physician at the University of Michigan. The faster that group is protected, the lower the risk that their bodies turn into incubators for the world’s next supercharged mutant.

“We should give the best shot we can, both literally and figuratively, to protect this population,” Lauring said.

That might be complicated, he added. For the same reason that these people don’t mount a strong immune response to the virus, vaccines might not work well in them. So they may need to be treated with cocktails of monoclonal antibodies as well, he said.

Like other viruses, the coronavirus collects mutations every time it replicates. The overwhelming majority of those genetic glitches are insignificant and transient. In most people, an active infection lasts only about a week, not long enough for the virus to acquire more than one noteworthy mutation, if any.

Mutations that make the coronavirus more contagious or enable it to dodge the immune system are extremely rare, researchers reported in a study published last week in the journal Science. “But if they do occur, and if they can get transmitted, then it’s open season,” said Katrina Lythgoe, an evolutionary biologist at the University of Oxford who led the study.

Over a period of months to years, the virus may string together several such mutations. Scientists can observe this slow evolution using a molecular “clock” that captures the changes over time. But in a person with a weak immune system, this timeline can be greatly accelerated.

“If we look at several time points through that course of infection, and we look at the virus population in that patient, we see — every time — different variants popping up with a large turnover rate,” said Vincent Munster, a virus expert at the National Institute of Allergy and Infectious Diseases who led one of the studies.

If one of these variants that has gained important mutations is transmitted to someone else, it may spread quickly through the population and seem to have emerged out of nowhere — as in the case of the variant that walloped Britain, and perhaps others identified in South Africa and Brazil.

“That’s a pretty decent hypothesis that they’ve come from people with persistent infection,” Lythgoe said of the variants. “By keeping infection rates low, you’re going to reduce the number of immunocompromised people who are infected and reduce the chance that they occur.”

“Immunocompromised” is a nebulous term encompassing a wide range of conditions — from diabetes and rheumatoid arthritis to leukemia and lymphoma — and experts disagreed on which conditions may lead to variants.

Some say the list should include older people, as well as those who take medications that suppress the immune system and anyone who does not produce a robust set of antibodies.

“We learned from the vaccines that antibodies matter,” said Paul Duprex, director of the Center for Vaccine Research at the University of Pittsburgh. “It’s very important to keep an eye on people who are immune-suppressed, who don’t have fully functional immune systems.”

Lauring said he was most worried about people with blood-related cancers like leukemia, but did not have strong concerns about those taking drugs like Humira or Enbrel, which are used to treat rheumatoid arthritis.

“It’s a different kind of immunosuppression that I’m not sure would lead to this, but no one knows for sure,” he said.

Some people with weak immune systems have been known to transmit other viruses over long periods, Lauring noted. One man in England has shed poliovirus for at least 28 years. Others have had persistent infections with norovirus or influenza.

“We’ve been dealing with this for a long time,” he said. “But just like everything with COVID, we’re dealing with it on a big scale.”

He and the other experts emphasized that regardless of the risks, it is important not to stigmatize or blame people who have compromised immune systems. Instead, they said, the focus should be on limiting their exposure to the virus.

“Let’s get the vaccines into people, let’s do good distancing, let’s do good masking,” Duprex said. “Everything that we can do to stop the virus spreading is really very important.