Over eons of time, rocks break down from the action of wind and waves and earthquakes and rain. That’s how the sand forms. The hotter the climate, the easier it is, since moisture tends to make the grains chohere. How deep is it? Usually several hundreds of feet deep. What’s beneath it? Certainly rock, plus underground streams, forgotten cities, and all the other detrius of mankind. How did it all accumulate in one place? Mostly the action of wind over long periods of time.