On Wednesday afternoon, Tunisia’s newly elected parliament was about to meet to discuss the country’s jihad problem. The goal was to discuss better methods to counter the growing threat coming from the country’s borders with Libya and Algeria. But parliament never got a chance to meet. The threat had already come home.

Wednesday’s attack at the National Bardo Museum, later claimed by the Islamic State group, killed at least 23 people, most of whom were tourists. It happened a short distance from the parliament, in a moment symbolic of how a nation that had come out of the Arab Spring as the sole stable country produced by those revolutions was now under direct terrorist threat.

President Beji Caid Essebsi declared in the aftermath that Tunisia was in a “state of war” against terrorism and that it would “fight without pity.” But that fight will not be easy. That’s because Tunisia doesn’t just have to combat the militants at home; it faces a major external threat.

“The broader Tunisian problem does not sit within its borders, it sits right outside,” said Seth G. Jones, director of the RAND Corporation's International Security and Defense Policy Center. "Even if the government can deal with the security problem inside of the country it does not have the capacity to deal with it in the region.”

On Thursday, the Tunisian government mobilized military and police forces, amped up security at tourist hotspots and planned to revise the portion of budget allocated to counterterrorism efforts and equipment. In addition, the government plans to be more vigilant with online surveillance and shut down jihadi forums and websites that some terror groups use for recruitment and for planning attacks.

While these security efforts are largely targeted toward Tunisia's internal terrorism problem, they may do little to combat the bigger threat coming from outside. The country is "being squeezed in a vise of extremism with Libya to the east and Algeria to the west,” the Soufan Group noted in Thursday’s IntelBrief.

At least 3,000 Tunisians have left to join ISIS, and many have left through the largely unmonitored desert border with Libya, where a civil war is raging and various jihadist factions have set up bases. In the past week alone, the Tunisian government said it has stopped at least 10 people from crossing the border into Libya to join jihadist groups including ISIS, which recently announced its presence there.

“They have been smuggling goods and trading illegally for decades. It will be very hard for the Tunisian government to secure the Libyan border,”said Karim Mezran, a senior fellow at the Atlantic Council, a Washington think tank.. “The Libyan problem has to be solved in Libya before you can seal the border with Tunisia. This makes Tunisia vulnerable no matter what.”

Tunisia is widely seen as the most successful state to come from the wave of movements in the region in 2011, but its neighbor Libya is a failed state. It has been in the throes of a civil war for months and this year has seen some of the worst violence since a 2011 revolution ousted dictator Moammar Gadhafi. It is home to two rival governments, dozens of militias ranging from secular to hardcore Islamist and various terrorist groups, all fighting for a piece of the country, and availing themselves of Gadhafi's enormous arsenal.

In order to secure the border with Libya, Tunisia is likely to ask for help from countries who share its concern over the terrorist threat and have helped in the past, or have the capacity to help now.

“Libya, probably being the egregious threat to Tunisia, that’s probably one area where the assistance from the Americans and the Europeans will be decisive,” Jones said, adding that some Western countries were already cooperating with Tunisia.

France and Tunisia have been working together to combat militants since November, sharing intelligence and police work. French interior minister Bernard Cazeneuve is set to visit Tunisia on Friday, to discuss the expanding security cooperation between the two countries.

Tunisia can also count on more than one Western friend to assist: “France definitely because of its closeness with the Tunisian and Algerian regimes. Italians because the vast majority of its tourists go to Tunisia,” Mezran said. “The U.S. because of its international role and England because of its capacity in counterterrorism.”

The Algerian government, fighting its own internal militants, has also been playing a key role in Tunisia’s counterterrorism operations, which is likely to increase as the two countries share a common threat from al Qaeda in the Islamic Maghreb, the North African offshoot of the terrorist entity. One of president Essebsi’s stated goals is to strengthen intelligence-sharing and security cooperation with Algeria, in order to secure the border from possible militant infiltration. Two days before the attack at the Bardo Museum, Algeria reportedly gave Tunisia a shipment of Russian-made missiles, according to the Middle East Monitor. This was just one of several weapon shipments Tunisia had received in recent months.

In February, Essebsi said that "cooperation between Algeria and Tunisia is at an ideal level and that if it wasn't for the security cooperation between the two countries, terrorism would have spread in the region."

Tunisia had taken a firm stance against terrorism well before Wednesday. In December, then-prime minister Mehdi Jomaa implemented new strategies that included a new counterterrorism force and a new organized crime division of the country’s security forces, according to “Jihadism in Tunisia: The Growing Threat,” by the Jamestown Foundation.

About 400 people have been arrested for ties to terrorist groups since Prime Minister Habib Essid took office last month. Military forces launched several operations to dismantle suspected terror recruitment cells in the country. According to analysts, Tunisia has been serious in tackling the threat. “The image that there is a deteriorating security situation is wrong,” Mezran said. “They have been patrolling, they have been arresting sleeper cells. But no country is safe 100 percent.

“They need more training, they need more support, they need more money,” he said. “But they have the capacity to do this.”