Prime Minister Margaret Thatcher pledged today that Britain would never give in to terrorist demands and called on the news media to adopt a "voluntary code of conduct" that would "starve the terrorists and the hijackers of the oxygen of publicity on which they depend."

In a sharply worded address to thousands of American lawyers gathered here for the American Bar Association's annual meeting, Thatcher said that no hijacked aircraft landing in Britain would be allowed to take off, no prisoners would be released, and "statements in support of the terrorists' cause will not be made."

Thatcher's remarks concerning the media reflected widespread concern here and in the United States that the extensive coverage of last month's TWA hijacking and seizure of passengers by Moslem extremists in Beirut provided an international platform that encouraged the hijackers.

While she noted that free societies were limited in the controls they could or should place on the press, Thatcher called for a media agreement "under which they would not say or show anything which could assist the terrorists morale or their cause."

In an earlier ABA panel discussion today, State Department legal adviser Abraham D. Sofaer voiced the most direct criticism of the media coming from the Reagan administration since the hostages were released. "The hijackers sought publicity," Sofaer said, "and they got it. The world was treated to a media extravaganza that gave irresponsibility and tasteleness a new meaning."

References to the media in both Sofaer's panel statement and Thatcher's speech brought loud applause from the audiences.

More than 10,000 American lawyers are participating in the six-day ABA meeting, the fourth held in London since 1924. The overall theme of the session is "Justice for a Generation." Many of the scheduled panels and discussions are focused on mutual U.S. and British legal concerns, such as trade, investment and tax issues.

But the central issue in the opening sessions was the need to implement existing legal means to prevent and punish international terrorists, and to adopt new methods of dealing with a growing threat.

In a panel discussion on terrorism led by former vice president Walter F. Mondale, Sofaer said that the United States has filed a "formal demand" that Lebanon take action against those responsible for the TWA hijacking, the holding of the 39 American hostages, and the murder of a U.S. citizen aboard the plane.

Sofaer said that U.S. Attorney General Edwin Meese, who was attending the sessions, "will determine when to file a formal demand for extradition" of the hijackers.

U.S. officials have indicated that, based on intelligence information, media reports during the crisis and interviews with the released hostages, at least some of those who participated in the hijacking have been identified.

Reports from Beirut last week that several suspects had been detained there subsequently were denied by the Lebanese government.

Asked whether U.S. authorities had moved to secure an indictment prior to an extradition request for persons believed responsible for the hijacking, another panel participant, FBI director William H. Webster said that such action would require "a grand-jury process."

Webster said such a procedure would be secret, and he could not say whether one was under way.

[Justice Department officials in Washington confirmed that investigation of the hijacking is being conducted by the Washington field office of the FBI and that evidence will be turned over to the U.S. attorney's office for presentation to a grand jury.]

Webster said "these are sensitive times right now," and he could not comment on whether the United States had provided Lebanon with any information, based on its own investigation, to assist in locating the hijackers. "I think the less we say publicly . . . the greater probability exists that the Lebanese will take their own action," he said.

While acknowledging skepticism, Sofaer said "we cannot know in advance that an effort to arrest the hijackers is bound to fail. Lebanon is a complex place . . . a good result could come about through circumstances we cannot now entirely anticipate."

In the absence of such result, he said, the United States would be "faced with the option of seeking action" under a resolution adopted by western industrialized nations in 1978 summit in Bonn. That resolution, he said, calls on the seven governments to "take immediate action to cease all flights" connected with any country that refuses to prosecute or extradite hijackers or to return a hijacked aircraft.

Thus far, Western Europe has resisted administration appeals to join in sanctions against Beirut airport and the Lebanese national airlines. "However persistently we pursue this course," Sofaer acknowledged, it is a difficult one, depending on seven nations, "each with independent interests and views."

"I'm sure that some if not most of you are thinking at this point: forget about law; let's just go in there and get the killers," Sofaer said, adding that the United States under existing international law is "entitled now to use necessary and proportionate force to end such attacks" and that "force will play its part."

"But the possible use of force should not distract us from the role that law can play in this struggle," Sofaer said. He called for the creation of "meaningful enforcement mechanisms" for existing antihijack agreements; amending the Bonn declaration to provide specific and swiftly imposed sanctions, and action to "overcome the reluctance even of civilized nations to extradite terrorists."

Thatcher praised U.S. efforts to end Irish-American support of the Irish Republican Army, saying, "We are also most appreciative" of a new accord between the two countries that would end U.S. prohibitions against extraditing those whose alleged offenses are classed as "political."