Two Cuban soldiers seeking to defect to the United States have been living in the American Embassy in Ethiopia for almost four months as U.S. efforts to get them safely out of that country have been thwarted.

The soldiers, said to be infantrymen in their early 20s, climbed over a fence around the U.S. Embassy in the capital, Addis Ababa, on the night of May 23 and, according to State Department sources, told embassy officials that they wanted to "get away from communism and go to the United States."

There are about 12,000 to 13,000 Cuban troops in Ethopia, part of an estimated 35,000 to 40,000 Cuban troops and advisers in several African countries. Officials here say they cannot recall any other case where Cuban soldiers stationed abroad have tried to defect

The situation, similar to one that developed this week in Afghanistan where a Soviet soldier is seeking refuge in the U.S. Embassy, has added to the strains between Washington and Ethiopia's Soviet-Cuban-backed government. It also could be an embarrassment for Cuba and a potential morale problem among its troops abroad.

The incident may also have been one of the factors leading to Ethiopia's demand in July that the United States recall its ambassador to Addis Ababa, Frederick Chapin.

The soldiers -- who are said not to have been engaged in any sensitive assignments -- were based at a Cuban outpost just outside the capital. Their climb over the fence occurred during the period when tens of thousands of Cuban civilians were being allowed to leave their homeland by boat for the United States.

Aside from Cuban troops, there are another 350 to 500 Cuban economic advisers in Ethiopia, according to U.S. estimates. There are also some 1,000 Soviet military advisers and another 1,000 Soviet economic advisers to the revolutionary Marxist government of Mengistu Haile Mariam.

Under generally recognized international rules, officials explain, embassies cannot grant actual political asylum to citizens of another country. What they can do is grant temporary refuge to persons fleeing political persecution and fearing for their life or safety. This is what the United States has done, with the hope of eventually providing political asylum here for the two defectors.

The 1951 United Nations Convention on Refugees puts an obligation on the country in whose territory the defection takes place not forcibly to send political refugees back where they came from.

State Department officials say that the United States tried to bring the U.N. High Commissioner for Refugees into this situation to interview the Cubans and help resettle them, but that the Ethiopians blocked this, claiming that it was not the U.N.'s role and that Ethiopia would handle this as a sovereign matter.

The Ethiopians, officials here say, want to decide for themselves if the Cubans fall into the category of political refugees seeking protection, and they want to interview the soldiers under strictly Ethiopian control.

U.S. officials say this country is reluctant to turn the soldiers over to exclusive Ethiopian custody, and so the situation remains stalemated with no solution in sight.

As a practical matter, there is no way for the United States to take the Cubans out of the country without Ethiopian permission and guarantee of safe passage. And, since the Cuban troops are in Ethiopia by "invitation" of the Addis Ababa government, it would be embarrassing to let the defectors leave.

another factor complicating the plight of the Cuban soldiers involves two or three Ethiopian "students" who were living in the United States and went back in June to attend a political conference. The United States had been undecided about providing reentry visas to the Ethiopians, who, officials here said, were not viewed as bona fide students and whose political activities here were suspect.

U.S. officials say that while Chapin was trying to discuss the Cuban soldiers with the Ethiopians, the foreign ministry was raising the case of the student visas. The U.S. sources say no explicit link was made between the two cases but it clearly had an effect on the atmosphere surrounding the situation.

Chapin, these sources said, continued to tell the Ethiopians that he was awaiting a State Department decision on the student visas.

Late in July, the Ethiopians denounced Chapin publicly and asked for his recall for allegedly campaigning against the revolutionary government, though no specific incidents were mentioned.

In August, the State Department decided against issuing new visas to let the students back in.

Also in August, U.S.-Ethiopian relations sunk to a new low after Washington announced agreement with Somalia, which has been battling Ethiopia for years in the disputed Ogaden desert, for U.S. military access to Somali ports and airfields.

This month, the Ethiopian government sent a letter to President Carter about the new U.S. military link with neighboring Somalia, describing it as "a dagger poised at the heart of Ethiopia."

U.S. officials say that because of the general shrinkage in the U.S. diplomatic presence in Ethiopia over the years, there is considerable room at the large embassy compound and the two Cubans are living in "reasonably decent" conditions.