A Customs and Border Protection spokesman, citing the pending litigation, declined to comment or answer questions, such as how frequently electronics searches uncover something that warrants action. But other current and former agency officials said that the total number of searches remains low considering there are nearly 400 million border crossings annually.

Stevan E. Bunnell, the top lawyer at the Department of Homeland Security from 2013 to 2017, said agencies should be judicious about how often they use their search powers. But he also cited scenarios in which it could be important to scrutinize the pictures or contacts on a traveler’s phone, even though agents would not be able to meet a probable cause standard if warrants were required. Such scenarios could include travel patterns or an intelligence tip raising the possibility that the traveler has links to terrorism.

Aristides Jiménez, who was a deputy special agent in charge of the Homeland Security Investigations office in San Antonio before retiring this year, said such searches have led to the arrests of drug and human smugglers as well as child pornographers.

“Believe me, it’s not something that ICE agents want to abuse,” he said, referring to Immigration and Customs Enforcement, another homeland security agency that conducts border searches. “Because we know in this environment, if you abuse the authority, you’ll lose it.”

The government redacted names from the complaints, but many identified themselves as Muslims or people who were not of European descent, and many appeared to be men. A Kuwaiti man, for instance, wrote that when his plane landed in the United States in September 2016, border agents came on board and asked him to unlock his laptop and phone.

“I told them my religion prohibits that other men see my wife without the hijab (the head cover) and in some pics she was partially nude,” he wrote, including the parenthetical explanation. But he was scared that they would “do something bad” to him and gave the agents the passwords to his devices.