They broke up an international movie piracy ring, returned the hand of an ancient mummy to Egypt and helped arrest the world’s biggest drug kingpin, Joaquin “El Chapo” Guzman.

Homeland Security Investigations, a branch within Immigration and Customs Enforcement, focuses on combating cross-border criminal activity and is billed as the investigative arm of the Department of Homeland Security. While many of its investigations involve immigrants, including some in the country illegally, many do not.

But its connection to ICE — at a time when the agency is under fire because of its role in deportations and enforcing President Trump’s aggressive immigration policy — has caused friction with some law enforcement agencies.

In California, where a “sanctuary” law, Senate Bill 54, went into effect last year to provide protection for immigrants in the country illegally, agents have voiced frustration over police departments pulling out from operations — sometimes at the last moment — as well as withdrawing from task forces and slowing down investigations.

“Now all of a sudden I have an agent in the street saying, ‘This police department doesn’t want to work with us because my cred says ICE,’ ” said Joseph Macias, special agent in charge for Homeland Security Investigations Los Angeles.

Trump’s hard-line stance on illegal immigration has provoked cities across the country to scrutinize agreements with ICE and, in some cases, end collaborations with the agency altogether.

“In the realm of everything that’s going on here in the sanctuary state with Senate Bill 54, it is absolutely making [agents’] job harder,” Macias said. “The boots on the ground, the guys that are doing the work, they understand it. We never want to violate any of the Senate bill’s pieces that are in there, but we want to make sure our guys are safe.”

One HSI agent recounted an operation last year that involved the arrest of a U.S. citizen in a narcotics investigation. Less than an hour before the man was supposed to arrive, LAPD officers were told to stand down, the agent said.

“We had to scramble, change our entire plan on the hood of our car. We did it with maybe six less people than we wanted to.… It was less than ideal,” said the agent, who declined to be identified because he was not authorized to speak to the media.

The political atmosphere has served to deepen long-standing tensions within the agency. This month, Homeland Security Investigations responded by expanding a program that immerses community members in weeks-long training sessions, known as citizens academies. These citizens academies, once held only in a handful of offices, including in L.A., are now required in all HSI offices in the U.S.

“I think this initiative will move the needle in a positive way more than anything else we do, in terms of trying to communicate and take a stand on where HSI is and what we do,” said Derek Benner, executive associate director for Homeland Security Investigations.

It’s a stroke of public relations that officials hope smooths a reputation that last June prompted 19 heads of HSI offices around the country to send a letter to Homeland Security Secretary Kirstjen Nielsen, requesting that the division break apart from ICE.

“HSI’s investigations have been perceived as targeting undocumented aliens, instead of the transnational criminal organizations that facilitate cross border crimes impacting our communities and national security,” the letter stated.

An agency born out of the merging of U.S. Immigration and Naturalization Service and Customs Service over a decade ago, ICE includes Enforcement and Removal Operations and Homeland Security Investigations branches. Agents liken the Homeland Security Investigations branch to the role the FBI plays within the Department of Justice.

HSI, which has grown to more than 6,000 special agents, has 30 field offices across the country. Their investigative areas include narcotics, child exploitation, money laundering, airport and seaport operations, export violations, computer crimes and trade fraud.

One of their investigations led to the indictment of 18 alleged members and associates of a white supremacist gang in Oklahoma.

The Enforcement and Removal Operations side focuses on enforcing immigration laws. Recently during an enforcement surge in the state of New York, ERO agents arrested 118 people for allegedly violating immigration laws. More than 100 were convicted criminals or had criminal charges pending, according to ICE.

The confusion between the two branches is long running, and HSI has struggled with a “branding problem,” said John Sandweg, who headed ICE under President Obama.

“There’s always been this perception that the ICE brand ... has tainted HSI as an organization and impaired their ability to do their job,” Sandweg said. “One of the biggest things that plagues ICE at large is how politicized it is as a law enforcement agency, and that’s only gotten a lot worse, obviously, in the last couple of years.”

Under the Trump administration, HSI received a directive to increase work site enforcement, which has played out with the arrests of immigrants in the country illegally at places such as a slaughterhouse in Tennessee and a trailer manufacturer in Texas.

Last year, the agency announced that ICE work site enforcement investigations in fiscal year 2018 had grown dramatically over the previous year. And during a non-immigration-related operation, agents won’t shy away from arrests of immigrants in the country illegally.

“If we’re in an operation and we’re doing a criminal search warrant and there’s somebody at a location and we read their name and they have a deportation order for a violent offense, we’re not going to walk away from it. We’re going to arrest that person,” said Jennifer Reyes, HSI assistant special agent in charge and organizer of the L.A. citizens academy. “But that’s not our primary goal. Our primary goal is criminal enforcement.”

Advocates say those examples show that HSI has a clear role in immigration enforcement.

“I’ve heard them say, ‘We’re different, we don’t do that,’ when in fact they also participate. But they’re complicated in that they do more than just immigration enforcement,” said Angelica Salas, executive director of the nonprofit Coalition for Humane Immigrant Rights of Los Angeles. “They’re trying to not get painted with the rightfully negative reputation of ICE, when in fact they’re also very important in immigration enforcement.… It’s like trying to deny themselves the scrutiny and the public concern, while still doing the work.”

Although there are more than 30 state and local agencies that continue to work with HSI and who “are still with us side by side,” Macias said, a few departments have pulled out of agreements over what he called “the politics.”

“The police officers that work on our task forces, they’re essential for what we do because they know the neighborhoods. We cover seven counties,” Macias said. “We can’t cover it all without our state and local partners.”

Benner said any issues occurred early on at a time when “the pressure publicly was at an all-time high in terms of the debate about sanctuary cities.”

“It kind of amped up people’s sensitivities to this and thankfully that didn’t last that long,” Benner said. “We kind of got back to what I would call business as usual, in terms of recognizing that as law enforcement we do better together.”

But he acknowledged that at meetings, agents have questioned what he plans to do to promote the HSI brand. Benner said he hopes the rollout of the citizens academies nationwide will help answer that question.

“The more contact that we can have with members of the community in this kind of intimate way — explaining what we do and how we do it in a very transparent manner — will answer that question of how will HSI become a more well-branded organization.”