Magnesium is very reactive metal like (Na, Ca, etc.). When it expose to air it reacts with oxygen to form a layer magnesium oxide (MgO) on its surface.
Mg + O2 → 2Mgo
This layer of magnesium oxide is quite stable and prevents further reaction of magnesium with oxygen. The magnesium ribbon is cleaned by sand paper to remove this layer so that the underlying metal can be used for the reaction.