As the Islamic State group loses territory in Iraq and Syria, one of its deadliest branches is struggling against Egypt's powerful army to maintain a foothold in the Sinai Peninsula.
The affiliate, known as Sinai Province, has waged a murky war in the north of the peninsula bordering Israel that has killed hundreds of soldiers and policemen.
It also claimed the bombing of a Russian airliner carrying holidaymakers from a south Sinai resort in October 2015 that killed all 224 people on board. Egypt's tourism has yet to recover.
But Sinai Province has been unable to seize population centres, with one attempt to occupy a town in 2015 ending with the military unleashing F-16 jets against the jihadists.
Instead the group has tried to keep up a steady war of attrition involving roadside bombings, sniper fire and checkpoint attacks such as the one on Thursday that killed eight soldiers.
The jihadists are increasingly encircled in the peninsula, with the military razing sections of a town bordering the Palestinian Gaza Strip to create a buffer zone and destroying tunnels there, while setting up checkpoints on routes out.
"The military's biggest success is that they have been able to contain the insurgency, by and large, to North Sinai," said Jantzen Garnett, an expert on the jihadists with the Navanti Group analytics company.
The army had been struggling to quash the insurgency that took off in 2013 after the military ousted Islamist president Mohamed Morsi, unleashing a bloody crackdown on his followers.
Three years into the insurgency, however, a decisive victory against the jihadists appears distant, as Thursday's attack suggests.
"The Egyptian army has made some short-term progress against (Sinai Province) over the past year but the militant group continues to adapt and this progress should not be construed as long-term success," Garnett said.
"The military upped up its presence in the Sinai following the July 1 attempt at taking over Sheikh Zuweid," analyst Mokhtar Awad said of the group's attempt to seize the north Sinai town in 2015.
The jihadists instead have "doubled down on types of operations focusing on trying to commit terrorist attacks... and focus on planting IEDs (improvised explosive devices) and more sniper attacks," said Awad, a research fellow with George Washington University's Program on Extremism.
They have also increased assassinations of officers and kidnappings and executions of suspected informants, in two cases publicly shooting them in the streets of North Sinai's capital El-Arish.
The military toll is difficult to verify. The military occasionally announces casualties, such as the eight soldiers killed on Thursday. Other reported casualties are not always disclosed.
In November alone, Egyptian media reported on the funerals -- held within a day of the deaths -- of at least 10 military soldiers and officers, not counting the eight killed on Thursday.
It is impossible to ascertain the toll among jihadists, who do not disclose their deaths. The military says it has killed hundreds of militants, occasionally publishing pictures of their corpses.
"It's always murky when it comes to assessing the picture in Sinai due to limits in verification," Awad said.
The organisation's hierarchy also remains a mystery.
In August, the military announced it had killed the group's top leader in Sinai, identified as Abu Duaa, without providing further details.
The moniker "Ansari"-- used by jihadists in Sinai for locals of the peninsula -- suggests he was a Sinai Bedouin.
A captured jihadi has said in interrogations that the identity of the group's overall leader in Sinai was unknown and he passed on instructions through a subordinate.
Under the leader -- known as a wali, or governor -- responsibilities are divided among militants who command "security," "military affairs," bomb-making and media sections.
The media commander is Shadi el-Menei, a well known Bedouin militant, according to the interrogations quoted in sections of a prosecution report seen by AFP. Others are identified by aliases.
Menei was a prominent leader of the group's forerunner, Ansar Beit al-Maqdis, before it pledged allegiance to the Islamic State in November 2014, the same year the group proclaimed a "caliphate" straddling Iraq and Syria.
Ansar Beit al-Maqdis had evolved from a loose militant group named the Mujahidin Shura Council, which conducted attacks on Israel in the chaotic year following strongman Hosni Mubarak's overthrow in February 2011.
The Shura Council had brought together jihadist Palestinian militants from the neighbouring Gaza Strip and local Bedouin veterans of groups that had conducted bombings against tourist resorts between 2004 and 2006.