I think that the only way out is that Ukraine cuts off its arm to save the head. It acknowledges the territories as lost, and consolidates what it has left. But I'm not sure how they do that without:
1. The current leader losing legitimacy, and likely resigning.
2. Opening the door for other parts of Ukraine to split off.
3. Opening the door to Russia to meddle in other parts of Ukraine/other nearby states to encourage them to split off.
I don't see Russia backing off in the near future; they've held onto Crimea for the last 8 years without blinking.
I don't see NATO involving itself militarily. If a US soldier dies defending Ukraine, I think that enough people will ask "why are we shedding American blood for something that has nothing to do with us?"
I don't know that economic sanctions will be enough. We've been doing that for years, and nothing's changed.
I don't know that providing weapons to Ukraine will be enough. While the Russians may lose soldiers in the coming months, I've heard that a lot of soldiers come from isolated parts of society (and so the people who mourn them aren't going to be able to organize political resistance).