Concerns run so deep that many have come to see the Taliban, which has also clashed with IS, as a potential partner in containing it. The Taliban and IS are sharply divided over ideology and tactics, with the Taliban largely confining their attacks to government targets and Afghan and international security forces

Jalalabad (Afghanistan): The Islamic State group has lost its caliphate in Syria and Iraq, but in the forbidding mountains of northeastern Afghanistan the group is expanding its footprint, recruiting new fighters and plotting attacks on the United States and other Western countries, according to US and Afghan security officials.

Nearly two decades after the US-led invasion, the extremist group is seen as an even greater threat than the Taliban because of its increasingly sophisticated military capabilities and its strategy of targeting civilians, both in Afghanistan and abroad.

Concerns run so deep that many have come to see the Taliban, which has also clashed with IS, as a potential partner in containing it.

A US intelligence official based in Afghanistan told The Associated Press that a recent wave of attacks in the capital, Kabul, is "practice runs" for even bigger attacks in Europe and the United States.

"This group is the most near-term threat to our homelands from Afghanistan," the official said on condition of anonymity to preserve his operational security.

"The IS core mandate is: You will conduct external attacks" in the US and Europe.

"That is their goal. It's just a matter of time," he said. "It is very scary."

Bruce Hoffman, director of the Centre for Security Studies at Georgetown University, sees Afghanistan as a possible new base for IS now that it has been driven from Iraq and Syria.

"ISIS has invested a disproportionate amount of attention and resources in Afghanistan," he said, pointing to "huge arms stockpiling" in the east.

The Islamic State affiliate appeared in Afghanistan shortly after the group's core fighters swept across Syria and Iraq in the summer of 2014, carving out a self-styled caliphate, or Islamic empire, in around a third of both countries.

The Afghanistan affiliate refers to itself as the Khorasan Province, a name applied to parts of Afghanistan, Iran and central Asia in the Middle Ages.

The IS affiliate initially numbered just a few dozen fighters, mainly Pakistani Taliban driven from their bases across the border and disgruntled Afghan Taliban attracted to IS' more extreme ideology.

While the Taliban have confined their struggle to Afghanistan, the IS militants pledged allegiance to Abu Bakr al-Baghdadi, the reclusive leader of the group in the Middle East, and embraced his call for a worldwide jihad against non-Muslims.

Within Afghanistan, IS launched large-scale attacks on minority Shiites, who it views as apostates deserving of death The group suffered some early stumbles as its leaders were picked off by US airstrikes.

But it received a major boost when the Islamic Movement of Uzbekistan joined its ranks in 2015.

Today it counts thousands of fighters, many from central Asia but also from Arab countries, Chechnya, India and Bangladesh, as well as ethnic Uighurs from China.

The group has long been based in the eastern Nangarhar province, a rugged region along the border with Pakistan, but has a strong presence in northern Afghanistan and of late has expanded into neighbouring Kunar province, where it could prove even harder to dislodge.

The mountainous province provided shelter for Osama bin Laden for nearly a year after the Taliban's ouster, and US forces struggled for years to capture and hold high-altitude outposts there, eventually all but surrendering the region to the Taliban.

The area comprising the provinces of Nangarhar, Nuristan, Kunar and Laghman was so dangerous that the US-led coalition assigned an acronym to it in the years after the invasion, referring to it as N2KL.

Militants launching shoulder-fired rockets from Kunar's peaks downed a US Chinook helicopter in 2005, killing 16 Navy SEALs and special operations forces in one of the deadliest single attacks of the war.

Ajmal Omar, a member of the Nangarhar provincial council, says IS now has a presence in all four provinces.

"Right now in Kunar, the right side of the road is Taliban, the left side is Daesh and the government is in the middle," he said, referring to the group by its Arabic acronym.

Speaking inside his heavily fortified home in the provincial capital, Jalalabad, he said neighbouring Kunar would soon replace the Middle East as the IS group's centre of gravity.

"When they began in Afghanistan they were maybe 150 Daesh, but today there are thousands and thousands," he said.

"The bad news is their acquisition of key terrain, height concealment, where they can have easy access to money, weapons, equipment . . .and from where they can plan, train, stage, facilitate and expedite attacks," said the US intelligence official.

"I think expansion of territory in eastern Afghanistan is their number one military objective," with the goal of eventually encircling Jalalabad, he said.

It's been nearly 18 years since the US invaded Afghanistan to topple the Taliban, which had harboured al-Qaida when bin Laden and his lieutenants were planning the September 11 attacks.

Now military and intelligence officials see the Taliban as a potential ally against a similar threat.

In recent months the Taliban have said they have no ambitions to monopolise power in a post-war Afghanistan, while IS is committed to overthrowing the Kabul government on its path to establishing a global caliphate.

The Taliban and IS are sharply divided over ideology and tactics, with the Taliban largely confining their attacks to government targets and Afghan and international security forces.

The Taliban and IS have fought each other on a number of occasions, and the Taliban are still the larger and more imposing force.