When Libya's eastern-based renegade commander Khalifa Haftar in April launched a military offensive to capture the capital, Tripoli, he knew he could count on the support of neighbouring Egypt.

Besides the prospect of winning lucrative reconstruction contracts, the Egyptian government's view of Haftar as a bulwark against the rise of political Islam boded well with its geopolitical interests in the region.

More:

But while Libya's eastern neighbour happily threw its weight behind Haftar, arming and providing the 76-year-old's forces with logistical support, the countries to the west - Algeria and Tunisia - opted for a different strategy.

Though nominally supportive of the internationally-recognised Government of National Accord (GNA) in Tripoli, Algeria and Tunisia have throughout Libya's near decade-long conflict maintained strict neutrality and insisted against foreign interference.

Speaking alongside his Tunisian counterpart Kais Saied in Algiers last week, Algerian President Abdelmadjid Tebbounereiterated the two countries' belief that the crisis could only end with a political solution that should come by Libyans themselves and "protected from foreign interference and weapons flows".

"Tunisia and Algeria want to make a solution for Libya with meetings in Tunisia or Algeria, to start a new stage there by building institutions and holding elections," Tebboune said.

Diplomacy over hard power

For many years, it seemed as though the two countries had avoided dealing with the conflict raging across their eastern border.

Some analysts have pointed to internal tribulations - economic stagnation in Tunisia and a latent political crisis in Algeria - to make sense of their apparent disengagement.

The inability of Tunisian authorities to translate democratic gains achieved following the 2011 overthrow of Zine El Abidine Ben Ali into tangible economic development resulted in major political instability, with 10 administrations having assumed power since.

Meanwhile, Algeria, seen by many as a regional powerbroker, could hardly make its voice heard after former President Abdelaziz Bouteflika suffered a debilitating stroke in 2013 that left him unable to address his people, much less represent his country's interests internationally.

For Akram Kharief, an Algerian defence analyst, domestic politics goes some way in explaining how Algeria deals with external crises, with instability in Algiers often seen by belligerents in Libya as an opportunity to revise the status quo there.

In February, just as tensions were rising in Algeria amid public discontent over Bouteflika's decision to run for a fifth term in office, Haftar launched a military push to seize much of southern Libya's Fezzan region.

In April, the leader of the self-styled Libyan National Army (LNA) began his assault on Tripoli, two days after Bouteflika was forced to resign by the military in the face of mass protests.

Ultimately, however, Algeria's refusal to engage militarily or lend its support to either of the warring factions is deeply rooted in the country's political tradition, which has historically prioritised diplomacy, Kharief said.

"Algeria's position in Libya is quite simple: It recognises the GNA but opposes any recourse to force. It also recognises Haftar who it sees as a stakeholder," he said.

"Since 2012, Algeria's been working towards a political solution between Libya's different parties and has relied heavily on dialogue between tribes to create a consensus from the bottom up."

That Algeria's strategy has failed to win the support of Libyans, Kharief said, is at least in part due to the jostling that has taken place among the half a dozen countries now supplying the warring factions with weapons in violation of a 2011 United Nations arms embargo.

In addition to Egypt, Haftar enjoys the backing of the United Arab Emirates, Jordan and Sudan. The UN-brokered GNA for its part is supported by Turkey.

'Tripoli a red line'

In January, just weeks after Haftar announced a renewed push to seize Tripoli, Tebboune declared the Libyan capital of 2.3 million people a "red line no one should cross".

According to Karim Mezran, a senior fellow at the Rafik Hariri Center, this is because Algiers does not think Haftar is capable of overtaking Tripoli.

"He [Haftar] can destroy the city. He can inflict a lot of harm and pain but I don't think he has the strength to hold the city," Mezran said.

Crucially, Algerians are concerned that the long battle for Tripoli will fuel instability along the porous, sparsely populated border region.

That could allow armed groups active in the area to regroup and stage attacks on Algeria's vital oil installations, as was the case in 2013 when an al-Qaeda affiliated group stormed the Ain Amenas gas plant near the Libyan border, forcing the Algerian military to intervene in an operation that left 39 foreign hostages dead.

Against this background, Algeria has recently engaged in a flurry of diplomatic activity, which recently saw it bring together in Algiers the foreign ministers of Libya's four bordering states aimed at stabilising the war-wracked country.

Tebboune had himself wasted no time in making known his country's concern with developments in Libya, attending peace talks in the German capital, Berlin, and receiving Turkish President Recep Tayyip Erdogan as well as Emirati Foreign Minister Abdullah bin Zayed within a month of the inauguration.

Joint security space

Just as important in Algeria's threat perception is the risk of further instability in Libya might have on Tunisia.

"Algiers and Tunis are closely linked," Kharief, the defence analyst, said. "Each includes the other in its security space, hence their convergent views."

Kharief said, "Tunisia is more at risk than Algeria because of trade ties and the greater presence of Tunisians in Libya and Libyans in Tunisia."

That was highlighted during a January meeting of Tunisia's National Security Council when Saied called for his country's authorities to step up preparations for an eventual influx of Libyan refugees.

Tourism, a vital sector that represents 8 percent of Tunisia's gross domestic product (GDP), took a hard hit after al-Qaeda affiliated gunmen in 2015 stormed a Tunis museum and beach resort in the coastal town of Sousse, killing 60 people.

The events that year led to a 25 percent decrease in the number of visitors and a 35 percent fall in tourism revenue.

Such attacks would also have an impact on Tunisia's political scene where the newly elected parliament has to date failed to agree on a government more than four months into its mandate.

"If Haftar pushes through and enters Tripoli, it will force many civilians to flee to Tunisia and cause major instability along the border. It will be a nightmare," Mezran said.

Exactly what more the two countries can do to stop the situation from getting worse is rarely discussed, and for good reason.

Algiers and Tunis have made it clear that under no circumstance will they entertain the idea of large-scale involvement of foreign troops in Libya.

Though foreign fighters have reportedly joined the battle for Tripoli, Kharief said no major escalation could take place without Algeria and Tunisia giving the greenlight.

"The Algerian military by its sheer force will prevent foreign powers from launching massive operations inside Libya," he said, adding that the two countries would for now have to contend with their geographic advantage to double down on the diplomatic track.