The U.S. effort to get foreign forces out of Lebanon is running out of time, and unless Syria eases opposition to a withdrawal agreement by the end of July, the administration probably will be unable to prevent Israel from pulling forces back to new positions in southern Lebanon, according to informed sources.

The U.S. campaign to coax Syria toward greater flexibility is tied to that time frame by the scheduled visits here of Lebanese President Amin Gemayel on July 22 and Israeli Prime Minister Menachem Begin on July 27, they said.

Begin will arrive under increasing pressure at home to redeploy the about 20,000 Israeli troops in Lebanon so as to lessen the risk of casualties from terrorist ambushes. Despite Israeli denials that a pullback has been decided, the sources said that David Kimche, director general of the Israeli foreign ministry, began to lay the groundwork for such a move in talks here last week.

Kimche is understood to have said that Israel will give the administration more time to try to convince Syrian President Hafez Assad to cooperate with the Israeli-Lebanese peace accord worked out by Secretary of State George P. Shultz last month. Under the agreement, Israel will not pull its troops out of Lebanon unless there is simultaneous withdrawal by Syrian forces and Palestine Liberation Organization units in Lebanon under Syrian protection.

However, if President Reagan is unable to show some evidence of Syrian flexibility when he meets Begin, the sources believe that Israel will insist it can wait no longer. Although Kimche is known to have said that Israel will consult the United States and Lebanon before any military redeployment, both Washington and Beirut fear that a unilateral Israeli move would have serious consequences for efforts to end the Lebanon crisis.

The sources said that at a meeting with Shultz yesterday, Gemayel's national security adviser, Wadi Haddad, expressed concern that an Israeli retrenchment would stiffen Syria's resistance to a withdrawal. That, in turn, would raise the threat of a permanent partition of Lebanon, with the Israelis occupying a security buffer zone in the south and the Syrians and the PLO controlling the eastern part of the country. That would effectively scuttle the Lebanese-Israeli withdrawal accord and undermine the efforts of the Gemayel government to assert authority over the divided country.

An Israeli pullback also would leave a void of authority in central Lebanon that could lead to a new outbreak of unchecked civil war between feuding Moslem and Christian factions.

But, while the administration shares these concerns, U.S. officials say there is little they can do to put pressure on Syria in the coming month. In fact, the officials concede, the United States still does not have a clear idea of whether Syria is unalterably opposed to a withdrawal agreement or is stalling in hopes of getting more leverage for concessions from Lebanon and Israel.

There has been increasing speculation that Shultz, who leaves this week for Asia, will stop in Damascus en route home in early July to meet with Assad. Some White House officials are understood to believe that efforts to arrange such a trip should be given top priority, even if the results are only symbolic.

However, State Department officials, while not ruling out the possibility, say that Shultz opposes the idea unless there are clear indications in advance that he could accomplish something concrete. And, these officials stress, the Syrians have given no sign they would be willing to deal with Shultz.

The other principal U.S. option is to try to induce Saudi Arabia, which gives Syria substantial financial support, to make a strong new effort to intervene with Assad. Haddad is understood to have urged that course in talks with Shultz yesterday.

However, in an interview here yesterday, Prince Talal, a brother of Saudi King Fahd, said his country already is working quietly behind the scenes and is doing "the maximum that is possible" to convince the Syrians to be reasonable.

Talal holds no official position in the Saudi government, and it was not clear to what degree he was speaking for the royal family. But the thrust of his message was that the United States must take the lead by establishing a "dialogue" with Syria and that Shultz should go to Damascus because he is the only U.S. official other than Reagan with sufficient stature to deal with Assad.