We report on the proof of principle of a scalable method for writing the magnetic state by electron-stimulated molecular dissociative adsorption on ultrathin Co on Re(0001). Intense microfocused low-energy electron beams are used to promote the formation of surface carbides and graphitic carbon through the fragmentation of carbon monoxide. Upon annealing at the CO desorption temperature, carbon persists in the irradiated areas, whereas the clean surface is recovered elsewhere, giving origin to chemical patterns with nanometer-sharp edges. The accumulation of carbon is found to induce an in-plane to out-of-plane spin reorientation transition in Co, manifested by the appearance of striped magnetic domains. Irradiation at doses in excess of 1000 L of CO followed by ultrahigh vacuum annealing at 380 °C determines the formation of a graphitic overlayer in the irradiated areas, under which Co exhibits out-of-plane magnetic anisotropy. Domains with opposite magnetization are separated here by chiral Neél walls. Our fabrication protocol adds lateral control to spin reorientation transitions, permitting to tune the magnetic anisotropy within arbitrary regions of mesoscopic size. We envisage applications in the nano-engineering of graphene-spaced stacks exhibiting the desired magnetic state and properties.