From studies of other stars which astronomers can see in many different stages of their 'life cycle', it seems pretty convincing from the data that the sun must have started out as a large collapsing cloud of gas inside some ancient interstellar cloud. This cloud was 'polluted' by a supernova several million years before the collapse phase ended, because we see certain isotopes of aluminum which could not have been a part of this cloud for very long unless they had been implanted by such an event.
The cloud collapsed for millions of years until it formed a rotating disk with a large central bulge. Out of the disk would eventually form the planets, and out of this central bulge where most of the mass wound up, formed the sun. We see such rotating disks of gas around many infant stars embedded in nebulae so this has confirmed this basic picture during the last 15 years or so. This isn't just 'theory' anymore.
The central bulge continued to collapse under its own gravity until deep in its interior the temperatures got so high...several million degrees....that deuterium atoms began to fuse and give off thermonuclear energy. This slowed the collapse down a bit and eventually led to a second stage where hydrogen nuclei could fuse into helium, which then started the sun's current evolutionary phase.
While all this was happening, the surface of the sun became very active and produced a powerful wind which blew out all of the remaining gas and dust in the surrounding disk of gas which had not settled into the bodies of the new planets that had formed. This 'T-Tauri wind' also scoured clean the atmospheres of the inner planets so that they were bare rock. Those that were volcanically active, however, were able to regenerate their atmospheres from the gases ejected by volcanic activity.
From start to finish, it took something like 100 million years to form the sun and planets from a collapsing cloud of gas, and this is not very long at all!!