You can have an ending in mind, but remember that even writers are advised:
Kill your darlings.
And we GMs are not even solo writers, though we share many of the same skills. As soon as making that ending happen and the actual game that's being played with your fellow players part ways, kill your darling ending with fire.
An ending that organically follows from the events of play will be infinitely more satisfying for everyone else than the ending that you had in mind. As the original writing advice explains (paraphrasing), "A bit of writing that you love is probably worse than you think because you can't be objective about it." Kill your ending as soon as it no longer serves a purpose and threatens to become a millstone around you and your players' necks.
What is a pre-written ending's purpose in a sandboxy game, then? It's something to aim for, direct your imagination, and breed hooks that make the beginning go well. It's a framework around which you can build an initial situation that will drive your end of the game, just as their character concepts drive the players' end of the game yet are subject to change and development. Once the game is off the ground and humming along, a pre-planned ending's purpose rapidly diminishes. It has given birth to its plot-hook children, and must gracefully step out of the way so that its children can inherit the game and pursue their own destinies, without parental meddling from the pre-planned ending.
Having an ending is, ironically, only really useful (in the sort of game you're talking about) for creating beginnings, and is a terrible way to create an actual played ending. For ways to create a good ending before a game fizzles out, you actually want to think more about putting a time limit on the campaign itself to focus it and give yourself a deadline for pacing purposes, and the players a deadline for accomplishing their goals. A campaign with an indefinite timeline almost always fizzles out rather than concludes, but a timeline with an ending that everyone is apprised of sharpens everyone's attention on giving stories a proper arc and bringing loose ends to a more-or-less tidy conclusion.