In Shafarevich's Basic Algebraic Geometry, he defines the structure presheaf on $\text{Spec}(A)$ first by $\mathcal{O}(D(f))\cong A_f$ and then $\mathcal{O}(U)=\lim_{D(f)\subset U}\mathcal{O}(D(f))$, where $f$ is an element of the ring $A$, $D(f)$ is a Zariski basic open set, $A_f$ is the localization of $A$ at the multiplicative set $\{f^n:n\in\mathbb{N}\}$, and $U$ is an arbitrary Zariski open set. Given $D(f)\subset D(g)$, he defines explicitly the map $\rho_{D(f)}^{D(g)}\mathcal{O}(D(g))\to\mathcal{O}(D(f))$ but put succinctly, it is the unique map $A_g\to A_f$ induced by the natural map $A\to A_f$ using the universal property of $A_g$.
Under this definition, we get the universal property for $\mathcal{O}(U)$ that if $R$ is any ring together with a collection of homomorphisms $\phi_f:R\to A_f$ for each $D(f)\subset U$ such that these maps commute with the homomorphisms $\rho_{D(f)}^{D(g)}$, then there exists a unique homomorphism $u:R\to\mathcal{O}(U)$ such that $\phi_f=\rho_{D(f)}^U\circ u$ for all $D(f)\subset U$.
However, this implies a universal property about $\mathcal{O}$ itself: If $F$ is any presheaf of $\text{Spec}(A)$ with restriction maps $res_V^U:F(U)\to F(V)$, such that $F(D(f))$ is naturally isomorphic to $A_f$ for all $f$, then there exists a unique natural transformation $\eta:F\to\mathcal{O}$ such that $res_{D(f)}^U=\rho_{D(f)}^U\circ\eta_U$ for any $D(f)\subset U$ (modulo the natural isomorphism $F(D(f))\cong A_f\cong\mathcal{O}(D(f))$). This suggests to me that there should be a way to write $\mathcal{O}$ as a limit of presheaves, but it is not clear to me how to do that. So my question is, is it possible to express $\mathcal{O}$ as a limit of presheaves (in a nontrivial way) and if so, how?
Question also asked on MathOverflow
Edit: I think I came up with a way to translate the universal property into limits. Specifically, $\mathcal{O}$ is the terminal object in a certain category.
Let $\mathcal{B}$ be the poset of basic open sets of $\operatorname{Spec}(A)$, and let $\mathbf{Psh}(X)$ denote the category of presheaves on a category. Let $r:\mathbf{Psh}(\operatorname{Spec}(A))\to\mathbf{Psh}(\mathcal{B})$ be the functor which restricts a presheaf on $\operatorname{Spec}(A)$ to the basic open sets, and let $\mathcal{O}_{basic}$ be the presheaf on $\mathcal{B}$ which sends $D(f)$ to $A_f$ (i.e. the structure sheaf only on basic open sets). Lastly, let $\mathbf{C}$ be the full subcategory of the comma category $r/\mathcal{O}_{basic}$ for which the morphisms to $\mathcal{O}_{basic}$ are isomorphisms (i.e. the objects of $\mathbf{C}$ are pairs $(\mathcal{F},\phi)$ where $\mathcal{F}$ is a presheaf on $\operatorname{Spec}(A)$ and $\phi$ is a natural isomorphism from $r(\mathcal{F})$ to $\mathcal{O}_{basic}$). Then $\mathcal{O}$ is the terminal object of $\mathbf{C}$. I don't know if there is a better way to express the universal property I stated as a limit than this, but I would be happy to hear it if there is.
There are two other ways to express $\mathcal{O}$ as a limit of presheaves or sheaves which I now know (neither or which is a direct translation of the universal property I stated). The first is to use the left adjoint to the restriction $\mathbf{Sh}(\operatorname{Spec}(A))\to\mathbf{Sh}(\mathcal{B})$ as explained in John's answer. The other way is to take Shafarevich's limit definition of $\mathcal{O}(U)$ as a limit and use the fact that a limit of presheaves is computed component-wise. Explicitly, let $F:\mathcal{B}\to\mathbf{Psh}(\operatorname{Spec}(A))$ be the functor which takes an open set $D(f)$ and sends it to the presheaf given by $F(D(f))(U)=A_f$ if $D(f)\subseteq U$ and $F(D(f))(U)=0$ otherwise. The restriction maps are all either the identity map or the zero map. Then $$\left(\lim_{D(f)\in\mathcal{B}} F(D(f))\right)(U)=\lim_{D(f)\in\mathcal{B}}F(D(f))(U)=\lim_{D(f)\subseteq U}A_f=\mathcal{O}(U)$$ and thus, $\lim_{D(f)\in\mathcal{B}}F(D(f))=\mathcal{O}$.