O2 is an oxidizing agent and Mg is reducing agent
2Mg + O2→ 2MgO
In the given reaction, O2 is reduced by losing oxygen atoms. Thus, O2 is an oxidizing agent as it undergoes reduction.
Mg is oxidized by gaining oxygen atoms. Thus, Mg is a reducing agent as it undergoes oxidation.