Human life on Earth will undoubtedly need to face many future challenges: bacteria that are resistant to antibiotics, violent volcanic "supereruptions," asteroid impacts and food shortages, among other possibilities. However, assuming that human ingenuity will be able to overcome many or even most of these expected perils (which may be a dangerous assumption to make), there are still a few events on a more cosmic scale that may be inevitable. The good news is that I'm referring to hazardous phenomena that are billions of years into the future.
The first of these catastrophes is likely to commence about 1 billion years hence. The amount of solar electromagnetic radiation hitting a unit area on the Earth's outer atmosphere is currently increasing (as the Sun evolves) at a rate of a little under 1 percent every 100 million years. Model calculations suggest that the Earth could begin to lose its oceans and experience a runaway greenhouse effect starting about 1 billion years from now. Eventually the Earth would revert to its original lifeless state.
The next major cosmic event affecting the environment of our entire solar system can be predicted with considerable certainty. Detailed measurements of the velocity of the Andromeda galaxy (M31) taken by the Hubble Space Telescope show that it will collide with the Milky Way in about 4 billion years (and the two galaxies will complete their merger in about 6 billion years). Figure 1 shows what the night sky might look like during the time leading to the collision. Simulations show that as a result of the head-on collision, there is an 85-percent probability that the solar system will end up at a larger radius than its current distance from the Milky Way's center. While it is not clear whether the change in the Sun's environment (in terms of the local density of surrounding stars) will have a direct effect on life on Earth, such a change is certainly possible, especially if nearby passages of other stars alter the solar system.
Figure 1. Sequence showing the expected view of the nighttime sky as the Andromeda galaxy collides with the Milky Way, in about 4 billion years.
Finally, the hydrogen nuclear fuel in the Sun's core will start to seriously deplete in about 5 billion years. Even if life manages to survive throughout the initial rise in the Earth's temperature (Earth will become hotter than Venus is today), it will be doomed in the next several hundred million years, as the Sun will evolve to become a red giant. At that stage the Sun will grow more than 100-fold in radius, and more than 1,000-fold in luminosity. While there is some uncertainty on whether the Earth would be physically engulfed by the expanding Sun, there is no question that the Earth will be scorched, experiencing temperatures well in excess of 1,000 Kelvin. By that time humanity (assuming it survives until then) will absolutely need to have found a new home.