SAN DIEGO — While they have their legitimate uses, drones have dropped drugs into prison yards, scouted out illegal border crossings, and grounded lifesaving aerial firefighting aircraft by wandering into their flight paths.

And local law enforcement agencies are looking for a way to bring them back to earth. A new electronic device called a “drone killer” could be the answer. Police in Oceanside, California, recently acquired the area’s first drone killer, an electronic device that can disable a drone in the sky and force it down.

“The purpose is primarily for emergency situations,” Oceanside police Lt. Aaron Doyle said. “It won’t be used when someone complains about a neighbor flying a drone. It’s pretty much for a life-or-death situation, to save lives.”

The need arose during last year’s wildfires when airborne firefighters were hindered by wayward drones.

The search led officers to IXI Technology in Yorba Linda, a company that has been supplying high-tech electronic equipment to the U.S. military and agreed to donate one of the drone killers, worth about $30,000.

The device, which looks like a gun, can be aimed like a rifle or a shotgun at a drone in the air. The 30-degree field of its beam and its range of almost a half-mile make the target hard to miss.

“In short, it breaks the command and control between the drone and the operator,” said Andy Morabe of IXI Technology.

The airborne drone, depending on how it is programmed, will do one of three things. It will either return to its “home,” which is the place it was launched, hover in place or go straight to the ground and land.

The company’s anti-drone device was first used by the Los Angeles County Sheriff’s Department to protect the 2017 Rose Parade, Morabe said. Since then, it has been used at a number of large public events around Los Angeles.

The device can stop almost any of the hundreds of models of remotely controlled aircraft that are available, Morabe said.

When a new drone is encountered that the device can’t defeat, the anti-drone software will be rewritten to include the new model and an update will be issued within days, he said. Operators can download the update from the internet, just like any new or updated app for a phone or computer.

Advancing technology and lower prices have led to a proliferation of drones in recent years, from the small ones with cameras sold online and in department stores to large ones used by the military to carry weapons.

U.S. penitentiaries, the Border Patrol, and the military are all interested in the anti-drone technology, he said. Marines at Camp Pendleton trained with the device just last month, according to a story by Reuters news service.

Law enforcement agencies across the United States are rapidly adopting the use of drones.

The San Diego County Sheriff’s Department became the first law enforcement agency in the county to use drones for surveillance in 2016. The eyes in the sky have assisted in dozens of homicide investigations, SWAT incidents and search-and-rescue missions.

The Chula Vista Police Department bought its first two drones this year, and police in Carlsbad and Escondido have said they are interested.

“It’s a great tool to use to find people who are missing,” Doyle said, whether it’s an Alzheimer’s patient who just walked away from home, or a criminal fleeing a crime. The drone has a heat-sensitive infrared camera to help locate people at night.

“Right now, we can only fly it during the day,” he said. “The program is still in its infancy.”

Officers are working to become certified by the Federal Aviation Administration and to establish local policies for when drones and the anti-drone device can or should be used.

Oceanside’s location next to Camp Pendleton Marine Corps Base, where training frequently causes brush fires, increases the need for a way to control drones during emergencies, Doyle said.

The Oceanside City Council gave its initial approval to a drone ordinance Nov. 1 and is still awaiting a final version. That ordinance, when finished later this year, is expected to prohibit drones over occupied schools and some other public places and may require a permit to operate drones in some situations.