US President Donald Trump recently spoke of the possibility of transferring migrants detained after crossing the US-Mexico border to so-called sanctuary cities, such as Los Angeles

A US appeals court on Thursday upheld a California "sanctuary state" bill that blocks state and local law enforcement from working with federal immigration authorities.

The three-judge panel of the Ninth Circuit Court of Appeals, headquartered in San Francisco, unanimously ruled to uphold Senate Bill 54, which prohibits police and sheriffs from collaborating with immigration authorities.

"SB 54 may well frustrate the federal government's immigration enforcement efforts," said Judge Milan Smith in the ruling.

"California has the right, pursuant to the anti-commandeering rule, to refrain from assisting with federal efforts," he added, referring to the 10th amendment of the US constitution, which says that powers not delegated to the federal government are given to the states or the people.

The decision upheld a July 2018 ruling appealed by the administration of US President Donald Trump.

The richest and most populous US state -- a Democratic stronghold where Latinos are the biggest demographic -- California is locked in a legal and political battle with the federal government, particularly on immigration and environmental issues.

Trump recently spoke of the possibility of transferring migrants detained after crossing the US-Mexico border to so-called sanctuary cities, such as Los Angeles.