This is called [Abiogenesis](https://en.m.wikipedia.org/wiki/Abiogenesis) and there is not an exact answer. The idea that life came from extraterrestrial origins is called [Panspermia](https://en.m.wikipedia.org/wiki/Panspermia) but it is not a substitute for abiogenesis as that still had to happen at some point.
The general process likely involved the formation by chance of simple self replicating molecules. As long as there was some error/variation in their replication then natural selection could act on them and lead slowly to the life we see today.
The most popular hypothesis for this is called [RNA world](https://en.m.wikipedia.org/wiki/RNA_world). RNA molecules can form spontaneously, we have detected RNA on asteroids which did not come from life, it was formed chemically by chance (we know this because it is [racemic](https://en.m.wikipedia.org/wiki/Racemic_mixture), or relatively racemic while life is entirely enantiospecific – i.e. we know its from chemical reactions not from aliens or contamination on earth). So we know RNA can form without life, we also know it can both store information (like DNA) and catalyze chemical reactions for self replication (like proteins). From there DNA eventually replaced RNA for information storage as it is more stable and protein replaced RNA for catalyzing reactions because it is more effective. However, RNA based enzymes are used by all life to make protein in the first place (ribosomes) and RNA is still the code directly read for cell functions, not DNA, which is strong evidence that life passed through an RNA world at some point.
The challenge is all direct evidence of early life on earth was destroyed by later life. So we have no way to confirm how abiogenesis occurred.
Latest Answers