https://en.m.wikipedia.org/wiki/Posse_Comitatus_Act
There are a number of situations in which the Act does not apply. These include:
National Guard units, state defense forces, and naval militias[17] while under the authority of the governor of a state. However, when the National Guard is federalized under 10 U.S.C. § 12406, that shifts control from the state governor to the President, making Guard operations subject to the Posse Comitatus Act as well.
Federal troops used in accordance to the Insurrection Act, which has been invoked 23 times, as of 1992.
Under 18 U.S.C. § 831, the Attorney General may request that the Secretary of Defense provide emergency assistance if domestic law enforcement is inadequate to address certain types of threats involving the release of nuclear materials, such as potential use of a nuclear or radiological weapon. Such assistance may be by any personnel under the authority of the Department of Defense, provided such assistance does not adversely affect U.S. military preparedness. The only exemption is the deployment of nuclear materials on the part of the United States Armed Forces.
Provide surveillance, intelligence gathering, observation, and equipment for domestic law enforcement on operations such as drug interdiction and counter-terrorism missions. For example, Delta Force soldiers from Fort Bragg were deployed upon request by the Federal Bureau of Investigation to serve as sniper/observer teams, run communications, provide medical support, gather intelligence, and conduct assistance in explosive breaching during the 1987 Atlanta prison riots.[18]