For five years the great wall of Morocco's King Hassan II has pushed outward across the former Spanish Sahara like a sidewinding snake.

At this outpost, less than six miles from the Algerian border, its sharp-edged ridges nine feet high stretch toward horizons where the sky is white with dust and the sand is the color of ash. The soldiers who live here in holes beneath the earthworks say the sun burns the rock until it is black.

Some observers called the wall a monumental folly when its first stages were pushed up in this brutal terrain in 1980.

But this massive barrier of sand, manned by tens of thousands of troops with sophisticated antipersonnel radar and guided antitank missiles now spans more than 1,500 miles. It has become the central element in an unusual strategy that appears to be winning decisively against an unusual insurgency.

A year ago Polisario guerrillas claimed to control two-thirds of the former Spanish Sahara. Now they claim less than one-third.

Within 10 days, according to Morocco's southern region commander, Brig. Gen. Abdelaziz Bennani, the barrier will be finished all the way from the ill-defined Algerian border to the Atlantic Ocean at a point near Dakhla.

If it succeeds in sealing out the insurgents there, Morocco can claim and demonstrate de facto control over all but the far south of the region, also known as Western Sahara.

At the same time, Hassan's decision to form a "union" with Libya last year appears to have ended Libya's extensive support for the insurgents. What they lose attacking the wall is increasingly difficult for them to replace.

In the last major engagement acknowledged by the Moroccans, the Polisario were reported to have been caught in cross fire 10 months ago as they breached the barrier a few miles from here. Bennani claimed 12 Polisario tanks were captured.

While the Moroccans are not yet claiming victory, they clearly are confident. To demonstrate its success this week, the Army took reporters from The Washington Post and two other U.S. papers on a guided tour of the wall.

There was virtually no opportunity to interview local residents away from government aides and thus no way of gauging popular support for the Polisario in the settled areas.

Yet there seemed little reason to doubt the impression shared by western diplomats in Rabat that the wall and the Libyan union have done serious damage to the Polisario guerrillas and their decade-old cause.

The fight for the region began in 1975 when Spain pulled out of its colony and Morocco moved in to occupy it as about 300,000 Moroccan citizens trooped through the desert waving their country's flag.

But some of the residents and nomadic tribesmen soon began a fight to turn it and its potentially rich phosphate and mineral deposits into their own Sahrawi Republic. Algeria and Libya backed them in an unusual guerrilla war.

The Polisario -- the Sahrawi army -- do not move in stealth with small arms but in armored columns with Soviet T55 tanks and armored personnel carriers. They claim about 20,000 fighters, but few western sources believe they have many more than 5,000.

Since 1977, when Bennani first came to the region, "the nature of the rebellion has changed," he said at his headquarters in Agadir. "In the beginning it was a matter of insurgents on foot and in jeeps. Now it's a matter of tanks and" SA6 surface-to-air missiles.

In 1981 a Moroccan C130 transport plane was downed by an SA6 missile, according to diplomatic sources. Bennani confirmed this and said such missiles are still used to protect the main Polisario camps south of Tindouf in Algeria.

Bennani and other officers shunned any analogy between this wall and France's World War II Maginot Line or Israel's Bar-Lev Line, both of which eventually proved useless.

This wall is different, according to Bennani, because it is always being moved outward. He called it a "mobile bridge" pushing through the desert until it reaches the borders of Algeria in the east and Mauritania in the south.

While guerrillas elsewhere can blend into the local population, in much of this desert virtually no local population exists. The wall has been used to separate the Polisario military forces from what population there is, Bennani said.

Little radar units on towers along the line also remove the advantage of surprise from the Polisario. Some of these can pick up a man moving on foot 16 miles away in the desert, according to officers here. Others, they said, can zero in on an artillery piece the minute the shells begin to land.

Bennani said some of the radar units are manufactured by Thompson, a French electronics firm that has a factory in Morocco. But others may have been provided by the United States, according to diplomatic sources.

According to official reports, the United States will give Morocco $43 million in military assistance this year. Much of the aerial surveillance along the lines is done with American equipment, Bennani said.

Another advantage of the wall is that Moroccan attack units deploying behind it cannot be seen by the Polisario, thus giving the Moroccans the advantage of surprise.

Politically, the key to Morocco's success thus far has been the surprise union with Libya signed at Hassan's initiative a year ago. Before that Morocco had suffered devastating diplomatic setbacks as more than 60 countries recognized the Sahrawi Republic.

The union between Hassan's relatively conservative monarchy and Muammar Qaddafi's radical regime has proved, for Morocco at least, a valuable marriage of convenience.

According to Bennani and several other top Moroccan officials, Libya now gives the Polisario nothing. "The wall has allowed us to economize on money and allowed us to relax a little bit," Bennani said.

According to officers along the line it is steadily forcing the Polisario to travel through Mauritania to mount attacks south of Dakhla.

Meanwhile, the military likes to point out that behind the wall its officers do not even bother to carry pistols, and at LaYoun, which was harassed by Polisario attacks before, Morocco has now opened a Club Med resort.