LONDON/ALGIERS The In Amenas gas plant felt impregnable to many who worked there - walled in, hundreds of miles from anywhere and with the Algerian army constantly patrolling its desert approaches.
That was a mirage. Libya, an ex-police state turned arms bazaar and now open for jihad, lies just 50 empty miles away. And in any case, the enemy was probably already inside the gates.
At least some of up to 70 Islamist guerrillas who stormed in before dawn on Wednesday launched their operation hours earlier, barreling over smugglers tracks across the Libyan border just after midnight, an Algerian security official told Reuters, citing evidence from mobile phones traced to the militants.
The ease with which they entered the fortified housing compound and nearby natural gas plant also left Algerians in little doubt the gunmen had allies among people at the site.
"They had local cooperation, I'm sure, maybe from drivers or security guards, who helped the terrorists get into the base," said Anis Rahmani, editor of Algeria's Ennahar newspaper and a writer on security issues who said he was briefed by officials.
Officials in this secretive country said they had discovered cases before when Islamist rebels succeeded in having fellow militants employed by international energy companies. One told Reuters it was possible insiders had cooperated at In Amenas.
Locally hired workers who escaped told Reuters of seeing the gunmen moving around the sprawling facility with confidence, apparently familiar with its layout and well prepared.
The militants said they launched the raid to halt French military intervention in neighboring Mali, which began a week ago, however the link is not yet clear. Several European and U.S. officials said the assault seems too elaborate to have been planned in such a short time.
It is possible the attack would have happened anyway, or that the French military operation provided a trigger to carry out an attack based on preparations done earlier.
Much may never become clear. The raid was carried out in a region closed to outsiders within a country whose government is unused to sharing sensitive information with the public.
First word of trouble came crackling over a walkie-talkie to the communications room at In Amenas, where a 27-year-old radio operator called Azedine logged a contact with a bus driver who, at 5:45 a.m. (0445 GMT), left to take some foreigners to the airstrip at the town of In Amenas, some 50 km (30 miles) away.
"Moments after the bus left, I heard shooting, a lot of shooting, and then nothing," Azedine told Reuters on Friday.
Two people, one British, one Algerian were killed on two buses heading for the airport. It is not clear whether that incident was part of the plan that secured the militants access to the compound. Almost immediately after the bus skirmish, they were inside, in at least three vehicles.
People who have worked at the site, which sits with its back to cliffs in the dunes, say there was normally an overnight curfew on movement in the area, leaving it unclear how the gunmen were able to get so close before being challenged. Their initial approach may have been well off the main roads.
Freed hostages spoke of an alarm being raised, of frightened people staying in their offices or accommodation.
Azedine saw a gunman put on the ID badge of a French supervisor who had been shot dead.
Rapidly the area was surrounded by heavily armed Algerian troops, with tanks, armored vehicles and helicopter gunships from a nearby military base. The government in Algiers vowed never to negotiate.
People familiar with the site, operated by Britain's BP and Statoil of Norway along with Algeria's state energy company, said a barracks housing several hundred soldiers lies along the three km (two miles) of road separating the many buildings of the accommodation compound from the industrial plant.
A former senior Algerian government official said guards appeared to have been caught napping: "They have all kinds of equipment, detailed surveillance, cameras," he said. "They were caught maybe at the right time, at five in the morning."
But he also acknowledged the militants may have had help among the local workforce: "Out of 700 Algerians, I am sure they will find a couple who will cooperate. It always happens."
Militant leaders like Taher Ben Cheneb, said by officials to have led the operation and to have been killed on Thursday, have stoked resentment among southerners at the way foreigners and northerners dominate the better paid jobs in the oil fields.
Ben Cheneb, described as a high school maths teacher in his 50s, led the Movement of the Islamic Youth in the South. Security expert Rahmani said he joined forces for this operation with followers of Mokhtar Belmokhtar, a veteran of Afghan wars and a leading figure in Al Qaeda in the Islamic Maghreb (AQIM) who recently formed a new group named Mulathameen.
The two men had cooperated before, Rahmani said, notably in damaging an airliner in 2007 at Djanet, further to the south.
While Ben Cheneb's group appeared to have moved on In Amenas from a base inside Algeria, Rahmani said, Belmokhtar's men, led by Abu El Bara, appeared to have come in from Libya.
Noting the one-eyed Belmokhtar's reputation as a cigarette smuggler as well as a holy warrior - locals call him the "Mister Marlboro" - he added: "They use the same backroads as the smugglers. You need a perfect knowledge of the Sahara to do it.
"They can use the same wells as the smugglers, the same fuel dumps hidden in the desert."
More than a decade after Algeria's civil war killed some 200,000 people, Islamist fighters roam the sandy wastes of Africa's biggest country, mixing smuggling and kidnapping for ransom with opposition to the political establishment that has ruled in Algiers since French colonists left half a century ago.
These groups have been energized by the return of heavily armed ethnic Tuaregs and others from Libya, where they fought as mercenaries for Muammar Gaddafi until his overthrow in 2011. The new Libyan authorities are struggling to control their own deep south and it provides a launchpad for raids across the frontier.
Images from Libya's civil war, of men in desert robes powering across the dunes in pick-up trucks mounted with heavy weapons ranging from machineguns to missile-launchers, have been transferred, along with arms and men, to conflict in the Sahara.
Mali's army melted away last year, ceding control of northern towns like Timbuktu as fighters came back from Libya.
While security forces seek to control their frontiers, the tracts of sand are vast, borders among the half dozen countries around the desert are unmarked, and the big money that can be made from illicit trade or kidnapping tourists and Western engineers can be used to buy favors from ill-paid officials.
Al Qaeda says it is fighting for a Muslim caliphate that transcends artificial borders in the Maghreb set by colonial powers.
Once inside the facility, militants, including bearded, ragged fighters and others in more urban dress, herded groups of Westerners together. Hundreds of Algerians were guarded more loosely. One Algerian worker told Reuters the gunmen said they were only interested in killing "Christians and infidels".
Several former hostages described the attackers, from their accents, as appearing to be Libyan or Egyptian as well as Algerian. Officials said many of 18 dead gunmen were foreign.
Algeria told Western governments, which voiced dismay at the storming of the facility on Thursday, that troops moved in only because guerrillas were trying to leave with hostages, possibly hoping to reach the Malian border.
The captors loaded hostages into a convoy. Special forces backed by helicopters moved in around noon, some 30 hours after the plant was seized.
In what appears to have been the deadliest part of the siege, as described by the family of Irish survivor Stephen McFaul, government forces bombed the convoy, blasting apart four vehicles full of hostages. McFaul was in a fifth truck which crashed. He dashed for his life and escaped, and believes all those in the other vehicles were killed.
During Thursday, most of the hundreds of people at the site were able to flee.
By Friday night, it remained unclear how many of the gunmen and their hostages were still in the facility - though both groups might number in the dozens. Norway's prime minister said the operation at the larger, residential compound seemed to be over and troops were now surrounding the industrial site.
But this left Western governments and intelligence officials, long used to difficult relations with Algeria which is proud of its sovereignty, desperate for hard facts about the fate of their nationals.