WASHINGTON (Reuters) - White House and congressional negotiators have reached a tentative agreement on an anti-terror spy bill that would permit court dismissal of potentially billions of dollars in lawsuits against phone companies, sources familiar with the talks said on Friday.

Under the possible accord, a federal court could immunize a company by ruling it had been given written assurances that its participation in the U.S. government’s warrantless domestic spying program was legal and authorized by President George W. Bush, one source said.

It was unclear what would happen with suits against the government. But the government could claim state secrets, arguing information needed to prosecute was confidential and that suits should thus be dropped, the source said.

About 40 civil lawsuits have been filed accusing AT&T Inc., Verizon Communications Inc. and Sprint Nextel Corp. of violating Americans’ privacy rights in the surveillance program begun by Bush shortly after the September 11 attacks.

“This is a terrible deal,” said Caroline Fredrickson of the American Civil Liberties Union. “It’s just a quick way to dismiss the cases. They (phone companies) just have to show that the president told them to break the law.”

The White House and Democratic-led Congress have been trying for months to reach an agreement to modernize the 1978 Foreign Intelligence Surveillance Act, which requires the government receive secret-court approval to conduct surveillance on foreign targets in the United States.

Critics charge Bush violated the law in authorizing warrantless surveillance after the September 11 attacks. But Bush maintains he had the wartime power to do it. He later put the program under FISA jurisdiction. Terms remain secret.

As part of any law to update FISA, Bush has demanded retroactive immunity for any telephone company that participated in his spying program.

But critics, including civil liberties groups, argued it should first be determined what the phone companies did before deciding whether to give them immunity.

Sources said congressional and administration negotiators had reach a tentative agreement and could finalize the deal by early next week, with a vote on passage shortly afterward.

But a congressional leadership aide cautioned: “Nothing is final. Things could still change.”

CQToday, a publication that tracks Congress, first reported on Friday that an agreement in principle had been reached on revamping surveillance rules and dealing with lawsuits against phone companies.

CQ also cautioned past deals have collapsed when negotiators agreed on what a proposed law should do, but disagreed on specific legislative language.

The proposed bill would replace a law that expired early this year that expanded the power of the government to conduct surveillance without wiretaps and keep pace with ever-changing technologies. Surveillance operations authorized under that law are to end in August.

The new measure is similar to one offered earlier by Sen. Christopher Bond, a Missouri Republican, a source said. A key difference is that a district court, not the secret FISA court, would decide whether to shield a phone company from a lawsuit.