MANAGUA, NICARAGUA -- Hernaldo Nunez Molina holds a job that is rare these days in Nicaragua. He manages the local office of an American company.

Only about two dozen U.S. corporations still maintain a presence here, mostly watching over investments made before the Sandinistas came to power in a 1979 revolution that brought broad economic changes.

Before the Sandinista takeover there were 168 U.S. businesses in Nicaragua, according to Ramiro Gurdian, president of the Nicaraguan Agricultural Producers Union.

About 30 American companies were confiscated by the government between 1979 and 1985.

With a badly deteriorating economy, along with a U.S. trade embargo and restrictive government policies, some U.S. companies have shut down on their own and others have sharply cut back their operations.

"The current economic conditions do make doing business in Nicaragua more complex," said Nadine Taylor, a spokeswoman for International Business Machines Corp.

The manager of one U.S. giant, who agreed to an interview on condition that neither he nor the company be identified, said the company has "too much money here" to walk away.

Because of government restrictions, its operations have been scaled back from 92 employes in 1979 to six now. Even so, the manager insisted, "we will stay."

Since the revolution, no major American companies have begun new operations. The largest U.S. operation is an oil refinery owned by Esso Standard Oil Ltd., an affiliate of Exxon Corp.

The 24-year-old refinery, the only one in the country, refines about 10,000 barrels a day of crude oil supplied by the Nicaraguan government, according to Exxon spokesman William D. Smith in New York.

"We will keep it running as long as it is economically feasible and as long as the U.S. government and the Nicaraguan government want us to stay," Smith said.

Virtually all Nicaragua's crude oil is supplied by the Soviet Union and its allies.

In addition to the refinery on the outskirts of Managua, Esso has 59 gasoline stations and 166 employes, none American.

IBM keeps about 25 employes on the payroll in its small office in Managua, mainly to provide maintenance service to customers.

"We have reduced our operations in line with the current economic conditions," said Taylor from IBM headquarters in Armonk, N.Y.

Xerox Corp. operates a small sales and service center, with about 50 employes.

"We've been there for 15 years and we're in business to stay," said Peter Hawes, a spokesman at corporate offices in Stamford, Conn.

"We have been having some difficulties, but we're beginning to overcome them," he added, without elaborating.

In doing business in Nicaragua, foreign companies have to contend with an economy badly drained by the war between the U.S.-supported contra rebels and the leftist Sandinista government, which came to power after overthrowing the pro-American, rightist Somoza dynasty that had ruled for 42 years.

Inflation has reached triple digits (657 percent for 1986), foreign exchange is scarce, and many managers and technicians have fled.

Unlike the hands-off policy for business that prevailed under the Somozas, the current government keeps a tight rein on the economy.

It regulates wages and prices, limits foreign exchange and has centralized the marketing of exports. Foreign companies generally cannot exchange their earnings in the local cordoba currency for dollars and send them home.

The government also has adopted strict occupational safety and environmental standards.

"Now, the rules of the game have changed dramatically," said Michael E. Conroy, associate director of the University of Texas' Institute of Latin American Studies.

Moreover, the Reagan administration in May 1985 imposed a trade embargo that effectively halted commercial relations between the two countries.

For private firms, the embargo has made it more difficult to get U.S. spare parts and machinery, although businessmen say they buy needed equipment and supplies through other countries.

Some foreign concerns, like banks and insurance companies, have had their operations sharply curtailed by government restrictions.

After the revolution, the new government nationalized domestic banks and barred foreign ones from taking deposits and offering checking accounts, limiting their activities mainly to loan collection.

"It was just a polite way to say, 'We don't need you in the market anymore,"' said an international banker speaking only on condition of anonymity.

Citibank, the United States' leading bank, suspended operations last year, although it did not formally close its doors, which were first opened in 1968, and is operating at a minimal level.

After more than two decades in Nicaragua, Bank of America closed last December. Its operations had been substantially trimmed back by July 1983, said spokesman Jim Mitchell in San Francisco.

Nunez Molina, general manager of the office of Texas-based Citizens Insurance Co. of America, has seen the agency's policyholders dwindle from more than 200 in 1979 to 57 now.

"They are canceling little by little," he said.

The Sandinista government has prohibited foreign insurance companies from selling new policies, allowing them only to collect on policies in force.

With the small amount of business he does out of his home, Nunez Molina said the parent company is "losing money with this office."

Among other U.S. companies that still have investments in Nicaragua, according to analysts, are American Standard Inc., Chevron Corp., H.B. Fuller Co., General Mills Inc., Hercules Inc., Intercontinental Hotels Corp., Kem Manufacturing Co. Inc., Nabisco Brands Inc., Texaco Inc. and United Brands Co.