PHILADELPHIA — To see friends this fall, Omaya Torres had to improvise. She couldn’t bring them into her dorm on campus, a pandemic rule that was strictly enforced. While a security guard watched at the entrance, a card-operated gate would open, then swiftly lock closed behind her, and a sensor would set off a warning alarm if another person tried to slip through.

She would meet her boyfriend and her friends at tables set up outside a building on her campus, where classes were mostly virtual all fall. As the weather got colder, she found a deserted lobby of a chain hotel, where they could sit and eat takeout from the noodle place next door.

But most of this first half of her senior year she has spent alone in her dorm. “The whole semester feels not real,” Torres said, “like I’m floating.”

But she is profoundly grateful to be on campus. Her dorm, despite the loneliness, is a haven.

She is one of a small number of students who were allowed to live on campus this fall at the University of Pennsylvania. As at many schools that closed dorms to help prevent the spread of the coronavirus, including some D.C.-area campuses such as American University, exceptions were granted for those who didn’t have good alternatives. For people facing complications, such as international students unable to travel home because of closed borders, or those from an unstable home, university housing provided a safe place to learn.

Some students, like Torres, will remain on campus over the winter break.

Life on an almost-empty campus can be surreal, an experience antithetical to the usual joyful buzz that permeates residential colleges, with the constant presence of friends, the last-minute decisions, good and bad, the laughs and the parties, the ideas traded in classrooms, the yelling at packed stadiums.

But for some students, it is essential.

LD Ross Jr., senior vice president of programs at the District of Columbia College Access Program, which primarily helps students from low-income families, said dorms can be a safer alternative for some students. On campus, they can have adequate housing, food and a secure environment.

He said a number of the students the program works with are in that situation, living in a dorm even though the school’s instruction is remote.

“Colleges and universities are doing a good job in terms of making sure that anyone they allow to come back on campus is adequately cared for,” Ross said. “Through the grace of God, we’re going to get through this, and our students will get through this.”

About 700,000 international students needed help in the spring and summer as the coronavirus spread worldwide, said Allan Goodman, president and chief executive of the Institute of International Education, “and most U.S. universities responded as they would have and should have to any student emergency.” His organization helped about 1,000 international students with emergency grants in the summer after borders were closed and air travel largely shut down. Many had expected to return home and work but had to remain in the United States without that income.

It was the first pandemic in the organization’s more than a century-long history to hit during the school year, and around the world. “Everybody’s borders closed, everybody’s air service stopped,” Goodman said, “and smack-dab in the middle of spring semester.”

Students at residential colleges are usually drawn to campus; that’s where their friends are. When East Carolina University in Greenville, N.C., pivoted to online classes after a surge in cases in August, for example, some 800 students chose to stay in dorms and log on from there.

But at schools that closed housing to most students, there were usually still some who didn’t have a way to get home, or a safe place to stay. The University of Southern California can house 9,000 students on campus but limited rooms to some athletes and students in need, for a total of 750 living in university housing this fall.

At American University, some 300 students have been granted emergency housing during the pandemic. That number has included those without stable housing, students whose homes were unsafe and those who didn’t have the technology needed to complete classes online.

This fall, AU added a few in-person classes with elements such as labs that were hard to replicate virtually, and allowed people in those classes, as well as some student-athletes and those with required ROTC training in the city, to live on campus, said Ashley Boltrushek, senior associate director of residence life at AU. A primary goal was to be flexible, she said, understanding that circumstances could change quickly during the pandemic.

At Penn, there would normally be about 5,500 students living on campus. This fall, there were 222.

Luis Ortiz Juarez, a senior at Penn, applied to stay on campus because home is a small apartment in Chicago where he would have to sleep and study in the living room, which his parents and sister would also be using, he said. He would have to get a job to pay for his own food at home, while at Penn, meals are covered by his financial aid.

Ortiz, who was born in Mexico and came to the United States with his family when he was 11, felt anxious about his relationship with his parents, and their strong religious convictions. “I’m also queer, so that doesn’t help,” he said. “I would be really uncomfortable if I were home.”

He is worried about the risk of the coronavirus, and grateful to have a safe place to live at Penn. “I have a good apartment, thankfully; my own kitchen, my own bathroom,” as well as steady WiFi and student health services close at hand.

It is isolating, though. “It’s quiet,” Ortiz said. “I rarely see people. I rarely interact with people.”

When Penn went virtual in the spring along with most other schools, Torres went to her family’s home in Philadelphia, where her mother and brother and sister live. Her mom, who is originally from Puerto Rico, is disabled and unable to work, so the whole family was crammed into the small space every day. There was no quiet place to study. Her own room is like a closet, she said, just big enough to hold a bed, so she took all her Zoom classes on her bed with the WiFi cutting out over and over throughout the day — including during exams.

“It was really super challenging,” said Torres, who is simultaneously finishing her undergraduate degree and beginning a master’s in public health at Penn’s Perelman School of Medicine.

The campus feels completely different than it did when she was living, eating and going to classes with friends every day, said Torres, who is a leader with Penn First, a group of first-generation and low-income students at the school.

Instead of thousands of people filling Locust Walk, the walkway that cuts through the heart of campus, just a few people hurried along on a recent afternoon, masks on and hats pulled low over their ears. Two men sat down, unloading plastic bags of takeout food, fumbling with their gloves. Poles that would normally be covered with signs for student clubs, lectures and performances were almost empty but for rusting staples.

Torres is worried about family members who are immunocompromised, so she has been careful. She has her own bathroom and kitchen in her dorm. “I got lucky,” she said. “Staying away from people now isn’t very difficult.”

She cooks most of her meals, usually Puerto Rican staples with the cheapest ingredients she can find, such as rice and flour.

Torres has been able to concentrate on classes too. She even found some advantages to Zoom: It was so much easier to connect with faculty online. She didn’t expect to excel in her biostatistics class, but she found herself going to office hours once or twice a week.

She had plenty of time to study. “I had nothing else to do!” she said, laughing. “And I got to really like it. It changed my career focus.”

Torres is very appreciative of Penn keeping her and others safe. “It’s a necessary sacrifice,” she said. “It’s worth it.”

But the semester has changed her. “I’ve just gotten so used to being isolated,” Torres said. “Before, I would actively seek out some kind of social interaction,” even if not the long, late nights talking with friends in her room the way things were in her freshman year. “I don’t have the motivation or energy to do it anymore. It just became so complicated.”

Before the pandemic, she and her boyfriend used to like going to a restaurant near campus, but this fall even the tables outside were much too crowded for safety, she said.

In December, after spending time with him outside and seeing the tips of her fingers turn blue in the cold, they decided to wait to get together until school reopens — they hope — for the spring.