The Mishna sates in Masechet Shabbat that one may not roast an egg using cloths which were heated by the sun. The Rabbis prohibited cooking on surfaces heated by the sun to prevent one from cooking on surfaces heated by fire.
The Maharshal (R. Shlomo Luria, 1510-1573) rules that this prohibition applies only to surfaces such as cloths, in which the source of the heat is not immediately apparent. That is, one cannot easily discern whether cloths were heated by the sun or fire, and therefore there is the danger that one may come to use cloths heated by fire. However, there is no problem cooking on surfaces which are fixed and directly exposed to the sun, because it is obvious that the sun, and not fire, was the source of the heat. Therefore, he permits cooking an egg on a hot roof, because it is obvious that the roof became hot from the sun.
The Magen Abraham (Rav Abraham Gombiner, Poland, 1637-1682) argues with this Maharshal, and prohibits cooking on a rooftop. The Mishna Berura concurs with the Magen Abraham. In fact, the Rambam (Hilchot Shabbat 9:3) explicitly prohibits cooking on hot sand. This directly contradicts the Maharshal, who would have to offer a different explanation for the Rambamís prohibition.
On Shabbat, it is prohibited to cook on any surface that was heated by the sun.