Secretary of State Alexander M. Haig Jr. yesterday refused to rule out possible U.S. attempts to overthrow the leftist regime in Nicaragua and said Congress is wrong to seek such reassurance for countries like Cuba and Nicaragua "that are moving toward totalitarian government."

"No, I would not give you such an assurance," Haig told the House Foreign Affairs Committee when Rep. Gerry E. Studds (D-Mass.) asked him to say the United States will not become involved in efforts to overthrow or destabilize Nicaragua's revolutionary Sandinista government.

He added: "But that must not be interpreted by mischievous inquisitors as articulation of our policy one way or the other. I think merely it would be a self-defeating statement by a responsible executive branch member."

Haig, in an appearance to discuss the whole range of administration foreign policy, was asked repeatedly whether the administration is studying military moves--a naval blockade of Nicaragua and show-of-force maneuvers near Cuba are among those that have been reported--to deter these countries from supporting leftist guerrillas in El Salvador.

In exchanges with committee Democrats that became quite heated, Haig would go no further than to note that President Reagan had addressed the issue in his news conference Tuesday when he said, "We have no plans for putting Americans in combat any place in the world . . . . "

"I think the president's statement should stand," Haig said. But his own comments about Cuba and Nicaragua were such that Rep. Michael D. Barnes (D-Md.) was moved to comment: "Based on your responses, if I were a Nicaraguan, I'd be building my bomb shelter."

Haig may have meant his remarks as a kind of psychological warfare against the Cubans and Nicaraguans. In much of what he said, he appeared to be trying to use uncertainty as to U.S. intentions to intimidate the Sandinistas and Cuban President Fidel Castro into halting their aid to the Salvadoran guerrillas.

Asserting that there is "an increasing level" of Cuban adventurism in the Western Hemisphere, he said the United States must demonstrate to Cuba and its backer, the Soviet Union, that such activities entail risks that "exceed whatever advantages they seek for themselves."

"I think it behooves the United States, as we have done, to make it clear to all concerned that this kind of activity is a profound danger to world peace and stability . . . I think it would only be prudent of the United States to view this activity with the utmost concern, as we do."

Attention was focused anew on the Caribbean and Central America by recent press reports that Haig, concerned about the apparent stalemate of the Salvadoran civil war, had asked the Pentagon to explore ways of cutting off the flow of weapons from Cuba through Nicaragua to the guerrillas in El Salvador.

Prior to yesterday, Haig had responded to questions about these reports by saying he was "not going to discuss issues under review." However, other administration officials privately have confirmed that possible military actions outside El Salvador have been under periodic study since February and that such studies were intensified in late summer, although the officials also have stressed that no decisions have been made.

Some administration sources also have said they believe a resort to military contingencies is unlikely, largely because Defense Secretary Caspar W. Weinberger and the Joint Chiefs of Staff are understood to have strong reservations. But, these sources added, Haig is unwilling publicly to rule out the idea at this time because he regards the uncertainty it has caused as an important weapon in his war of nerves against Cuba and Nicaragua.

In his exchange with Studds yesterday, Haig denounced "the growing totalitarian nature" and internally repressive tactics of the Sandinista regime and said: "It seems to me, Mr. Studds, that you should be concerned about the mounting evidence of authoritarianism in Nicaragua . . . . That's the fact of it, and I am shocked that you haven't even mentioned it."

Similarly, when Barnes also asked for assurances that no overt or covert actions are contemplated, Haig replied: "I'm not prepared to say anything of that kind . . . . If you are trying to reassure those regimes that are moving toward totalitarian government, I question if we're on a sound course."

After the hearing, Barnes, chairman of the House inter-American affairs subcommittee, said: "He was clearly trying to raise the level of rhetoric and increase the level of tension in the area, among our friends as well as our foes. I'm surprised in the light of the president's statement Tuesday when he appeared to be trying to calm things down. Each time Haig was given an opportunity to follow the president's lead, he seized it to raise the tone of hostility."

In his testimony on other aspects of world affairs, Haig said:

* The United States remains firmly committed to the Camp David accords as the principal vehicle for achieving peace in the Middle East, and the administration will not abandon that process for a Saudi Arabian plan that has been pronounced unacceptable by Israel.

* He is optimistic that an agreement will be worked out soon enabling Britain, France, Italy and the Netherlands to contribute troops to the peacekeeping force that will patrol the Sinai peninsula after Israel returns that territory to Egypt next April.

* The recent wave of peace demonstrations in Western Europe "does not mean that our European allies are going neutral" or that they will abandon the North Atlantic Alliance.

* When asked whether the United States promised to provide a protective umbrella for Egypt if it attacks Libya, he replied, "No, there is no such commitment."

* He asserted that quiet diplomacy by the United States and its allies has caused South Africa to agree to a negotiating program "that would visualize the independence of Namibia by 1982," and he added: "I think that's a remarkable accomplishment."