The magnetic field of the earth is surrounded in a region called the magnetosphere. The magnetosphere prevents most of the particles from the sun, carried in solar wind, from hitting the earth.
The magnetosphere shields our home planet from solar and cosmic particle radiation, as well as erosion of the atmosphere by the solar wind - the constant flow of charged particles streaming off the sun.