In Görtz and Wedhorn's Algebraic Geometry I, there's the following proposition:
Proposition 3.4. Let $(X,\mathcal O_X)$ be a locally ringed space. If $Y$ is an affine scheme then the natural map below is an isomorphism $$\mathsf{Hom}(X,Y)\overset{\cong}{\longrightarrow} \mathsf{Hom}(R,\Gamma(X,\mathcal O_X))$$
A proof is given only for the case where $X$ is a scheme, and proceeds by reducing to the anti-equivalence of affine schemes with commutative rings and then gluing the morphisms.
For the general case, the authors cite Prop 1.6.3 of the 1971 edition of EGA I, to which I don't have access. Can anyone reproduce/explain the proof?