The campaign ends with the final objective as saving the sun from supernova after a good while of gameplay.
The sandbox is endless and is akin to a "survival" mode. It can end when you choose, with self-assigned objectives (e.g. I want 20 planets then im done, or I want to defeat 3 enemies on Hard).
You can lose the games through loss of planets, end of the stars lifetimes and being over-run by the enemy.
I am also in the process of adding "Stress levels" of overall scientists, when stress reaches 100% a scientific disaster can occur and end the game. You can battle this with social space stations, solar malls and other luxury constructions.