TUCSON — I found myself on a desolate desert road, in front of a man who was leaning against the hood of a banged-up sedan and next to a United States Border Patrol agent who was on the radio of her patrol vehicle, running the sedan’s license plate.

In this virtual reality role-playing exercise in a Border Patrol simulator, my job was to keep an eye on the man.

He seemed nervous. His legs twitched. His eyes darted from side to side, as if he were searching for a chance to escape.

Suddenly, he walked to the driver’s side window of the sedan and reached inside.

I pulled my pistol from its holster, pointed it at him and yelled: “Sir, get back to the hood of the car! Get back to the hood of the car!”

Jason Daniels, an agent with the United States Border Patrol, instructing Fernanda Santos last week during a virtual reality exercise in Tucson. Credit Deanna Alejandra Dent for The New York Times

Jason Daniels, an agent with the United States Border Patrol, instructing Fernanda Santos last week during a virtual reality exercise in Tucson. Credit Deanna Alejandra Dent for The New York Times

The whole thing felt real, and that was exactly the point. The idea of the simulator is to immerse agents in the type of tense situations that they are likely to face on the job, and put their judgment and reactions to the test.

Will the suspect comply with a command? Will the agent pull the trigger?

The situations are based on real-life events. The difference is that, on the simulator screen, the interactions unfold based on the agents’ responses.

“We want to know, what did you see?” said Jason Daniels, an instructor who trains Border Patrol agents. “Why did you react that way? What else could you have done?”

Since the fatal police shooting of Michael Brown in Ferguson, Mo., in 2014, and a series of police shootings that followed it, a debate has erupted over the use of force by local police departments. The border with Mexico is also not immune to violent confrontations with law enforcement.

According to one tally, more than 30 people have been fatally shot by agents along the southern border since 2010, and several others have been injured in shootings. One of the victims, a Mexico-bound truck driver, was shot on Thursday by Border Patrol agents who said he had swerved his vehicle toward officers working at the Mariposa Port of Entry in Nogales, Ariz. He remained hospitalized on Sunday.

There are also numerous complaints of harsh treatment by Border Patrol agents. Some people who live and work near the border say they have been unjustifiably searched and detained at checkpoints. Migrants claim they have been held at Border Patrol stations in crowded, unsanitary cells that are so cold they have come to be known as hieleras, Spanish for iceboxes.

Pistols that fire lasers are used in virtual reality exercises to teach Border Patrol agents how to defuse potentially violent confrontations. Credit Deanna Alejandra Dent for The New York Times

Pistols that fire lasers are used in virtual reality exercises to teach Border Patrol agents how to defuse potentially violent confrontations. Credit Deanna Alejandra Dent for The New York Times

Border agents are also attacked. Smugglers often hurl rocks at agents to distract them while drugs are brought into the United States at another spot.

On Friday, the Tucson Sector of the United States Border Patrol, which is in charge of guarding 262 miles of the Arizona-Mexico boundary, invited six reporters to try the simulator and some of the less lethal weapons that agents have at their disposal. These were stun guns, collapsible batons and the rifle-style FN-303, which one agent described as “a pepper-ball launcher on steroids.”

The sector’s chief patrol agent, Paul A. Beeson, said that on a typical day, about 20,000 agents working along the borders with Canada and Mexico made 980 arrests and seized 9,000 pounds of drugs.

“During the course of all of that activity,” Chief Beeson said, “there are times when use of force is necessary.”

Under pressure by civil rights groups, the Border Patrol’s parent agency, Customs and Border Protection, refined its use-of-force policies two years ago. One goal was to train agents to think of other weapons, and other tactics, they could use to defuse potentially violent encounters.

“Don’t get caught up in the moment and put yourself n a situation where you have to respond with force,” said Mark McComack, the operations officer at the Tucson Sector.

The virtual exercise is a big part of that training. There are 135 Border Patrol stations in the country and 27 simulators; two are in the Tucson Sector, which is the largest station on the southern border.

The simulator feels like the video games in which each player is part of the action. The screens are tall and wide, arranged side by side in a pentagon. The gun, a Heckler & Koch semiautomatic pistol, was real but had been retrofitted to shoot laser beams when you pull the trigger. Instructors can see where the virtual bullets hit and what should happen next.

When the man I had been watching stuck his hand inside his car, I moved my finger to the trigger and yelled one more time: “Step away from the car.” He did, throwing his hands up.

The exercise was over. My hands were sweating. I didn’t shoot. But I had missed a critical piece of information: The car the man was driving had been reported stolen.

“You were so focused on what was happening in front of you, you tuned out the rest,” said the instructor, Agent Daniels. “That’s very common in the field.”

In real life, the events that the exercise was based on turned out much differently. The man did not surrender. Three years ago, in Hogg County, Tex., he pulled out a gun from inside the car he had just stolen and started shooting. The agents shot back. They were uninjured. The man did not survive.