The latest U.S.-Pakistan confrontation on the Afghanistan border underscores what could become a recurring problem if we do not learn how to manage the tension between working with Pakistan and taking stronger action against insurgent sanctuaries in that country. The U.S. effort in Afghanistan is making progress, but on the current timeline it is likely to fail if sanctuaries remain inviolable.

On my most recent trip to Afghanistan I found improvement. The Afghan army is growing and will be better by 2014. Insurgent expansion into the north has been contained. District and provincial government positions are being filled. Despite periodic high-profile attacks, the Taliban was unable to disrupt a recent three-day gathering of more than 2,000 Afghan notables in Kabul. If time and money were unlimited, this progress would be reassuring. But they are not.

The United States relied on building Afghan forces to handle the remaining violence, but that buildup began only in 2009. The Obama administration now has withdrawal written all over it; aid is declining and troops are leaving. We don’t even know how many troops President Obama will leave in 2013.

As time runs out, do we soldier on with little chance of success? Or do we pull out, watch a civil war destabilize South and Central Asia, and ignore the neighborhood’s further radicalization as Pakistan seeks to dominate Afghanistan? Al-Qaeda may well return, along with the Taliban.Evidence of tight links between the two is increasing. Someone with access to material from Osama bin Laden’s computers told me that even he was surprised at how tightly they were coordinating. The options — muddling along or quitting — are unpalatable.

There is, however, a third choice: becoming more confrontational toward Pakistan while understanding that destabilizing a nuclear-armed nation that is much larger than Afghanistan is absolutely not in our interest. That is why we should not use sanctions, cut off aid or designate Pakistan a terrorist state. We need to recognize that Pakistan has multiple goals, only some of which are opposed to ours. Like us, Pakistan wants to control extremism within its borders and has lost several thousand soldiers combating domestic militants without winning a decisive victory. It may not have the capacity to defeat those enemies, let alone the militants it protects in the hope of one day securing its interests in Afghanistan. This is why solely pressuring Pakistan to act in ways it neither wants nor is capable of is not likely to succeed or help our interests.

The alternative is to begin going directly after the sanctuaries — not all at once but slowly, with increasing missile and air attacks. The aim would be to degrade them, put militants on the run, disrupt the serenity of leaders who send their forces into battle while they remain safe, and make clear that Pakistan cannot safely retain the insurgent card for later use. We should press Pakistan to aid the effort while expecting an angry initial reaction. Truck convoys would get burned; the Afghan border would be closed, at least temporarily , as it is now. We would have to prepare to answer such measures with even more attacks, including hitting the sanctuaries in Baluchistan (despite Pakistan’s vehement objections) to show our resolve. Islamabad might ban the flights that bring our munitions to Afghanistan. One answer would be to fly anyway with fighter escorts.

This policy would be highly dangerous. Pakistan’s military will not bend easily. Its support for Afghan militants is as deeply embedded as the conviction that only such allies can prevent Afghanistan from becoming an existential threat. To control tension with Pakistan we would need attacks in the border areas over time — not a one-time strike or ground invasion and certainly not hitting Pakistani troops — and do it while maintaining economic assistance and other help to Pakistan. Both confrontation and assistance have to be maintained, with care on which is emphasized at any particular moment. The quiet message to the Pakistani military would be: It’s your choice — you can stay in power and we’ll help you, but if the sanctuaries aren’t brought under control we’re going to hit them harder, even if that causes you pain.

This policy would not solve the poor governance in Afghanistan, a separate, critical issue that we will not get to if we lose on the battlefield. And this approach could leave Afghanistan and Pakistan in turmoil. It is not an approach I advocated when I was in Afghanistan — when our time horizons seemed longer — or one I would choose now if Washington had the will to remain engaged. But would its risks be worse than losing after 10 years of war, being faced down by a small, vicious group of insurgents allied to al-Qaeda and watching the whole area in chaos for years? Top military and civilian officials in Afghanistan say the option is to defeat sanctuaries and succeed, or ignore them and lose. Our choices are that stark.

Ronald E. Neumann was U.S. ambassador to Afghanistan from 2005 to 2007 and is the author of “The Other War: Winning and Losing in Afghanistan.”