Do we have $(f^{-1}(\mathcal O_{\operatorname{Spec}A}))(\operatorname{Spec}B)=A$? Given a morphism of schemes $f:\operatorname{Spec}B\to\operatorname{Spec}A$, do we have $(f^{-1}(\mathcal O_{\operatorname{Spec}A}))(\operatorname{Spec}B)=A$?
 A: No, suppose $A = k[x]$ and $B = k[x] / (x)$ for some field $k$, and $f$ corresponds to the quotient map $A \to B$.  Then $\Gamma(\operatorname{Spec} B, f^{-1}(\mathcal{O}_{\operatorname{Spec} A})) \simeq k[x]_{(x)}$.
A: If $i$ is the inclusion of an open subset $U$ of a scheme $X$, then $i^{-1}\mathcal O_X = \mathcal O_{X|U}$.  In particular, $i^{-1}\mathcal O_X(U) = \mathcal O_{X|U}(U) = \mathcal O_X(U)$.  With this in mind, you get a counterexample by letting $f$ be the inclusion of a principal open subset into an affine scheme.
A: I believe the following holds: If $f: X \rightarrow S$ is a map of schemes and if $p \neq q\in X$ are points with $f(p)=f(q):=s \in S$ you get a canonical isomorphism
$$f^{-1}(\mathcal{O}_S)_p \cong \mathcal{O}_{S,s}\cong f^{-1}(\mathcal{O}_S)_q.$$
Since $p \neq q$ we do not have an isomorphism
$$ \mathcal{O}_{X,p}\neq \mathcal{O}_{X,q}$$
in general. Hence $f^{-1}(\mathcal{O}_S) \neq \mathcal{O}_X$ in general.
Question: "Do we have $f^{-1}(Spec(A))(Spec(B))=B$?"
Answer: We have a canonical map
$$f(Spec(B)): f^{-1}(\mathcal{O}_{Spec(A)})(Spec(B)\rightarrow \mathcal{O}_{Spec(B)}(Spec(B))\cong B,$$
but since the sheaves $f^{-1}(\mathcal{O}_{Spec(A)})$ and $\mathcal{O}_{Spec(B)}$ differ the map $f(Spec(B))$ is not an isomorphism in general.
Note: If there is a spelling mistake in the question, and we replace $A$ with $B$
the answer is positive when the map is an open immersion:
There seems to be some confusion on an exercise on adjoint functors.
If you look in Hartshorne Chapter II.1 you will find for any map of topological space $f: X\rightarrow Y$ (exercise 1.18) an isomorphism
$$M1.\text{   }Hom_X(f^{-1}G, F)\cong Hom_Y(G, f_*F).$$
Hence if $F:=(\tilde{f}, f^{\#}): X \rightarrow S$ is a map of schemes there is canonically a map of sheaves of rings on $X$:
$$f: \tilde{f}^{-1}(\mathcal{O}_S)\rightarrow \mathcal{O}_X.$$
The map $f$ corresponds to the map
$$f^{\#}: \mathcal{O}_S \rightarrow \tilde{f}_*\mathcal{O}_X$$
via the isomorphism $M1$. If $X:=Spec(B), S:=Spec(A)$ it follows the map $f$ is a map of sheaves of rings on $X$, not on $S$. Hence it does not make any sense to evaulate $f$ at $S$, since $S$ is not an open set in $X$. It only makes sense to evaluate $f$ at $X:=Spec(B)$. Moreover $A$ is not a subring of $B$ hence you never recover $A$ from $\mathcal{O}_X(U)$ or $\mathcal{O}_X(X)$.
Example 1. Let $S:=Spec(A), X:=D(f)$ for $f\in A$. We get an inclusion of the basic open set $D(f)$ into $S$:
$$\tilde{i}: X:=D(f) \rightarrow S$$
and a canonical map
$$i: \tilde{i}^{-1}(\mathcal{O}_S) \rightarrow \mathcal{O}_{D(f)},$$
and the map $i$ is an isomorphism: You may check that $\tilde{i}^{-1}(\mathcal{O}_S)\cong \mathcal{O}_{D(f)}$. In this special case you get an isomorphism
$$ i(D(f)): \tilde{i}^{-1}(\mathcal{O}_S)(D(f)) \cong A_f \cong\mathcal{O}_{D(f)}(D(f)),$$
but you do not get an isomorphism in general.
The natural question to ask is: for a general map of rings $\phi: A \rightarrow B,$
Question: Is the canonical map
$$f(X):\tilde{f}^{-1}(\mathcal{O}_S)(X) \rightarrow \mathcal{O}_X(X) \cong B$$
an isomorphism?"
Answer: The answer is "no", by the argument given in the previous post.
Note: if you take the "pull back"
$$F^*(\mathcal{O}_S)$$
you get
$$F^*(\mathcal{O}_S):= \mathcal{O}_X \otimes_{\tilde{f}^{-1}(\mathcal{O}_S)} \tilde{f}^{-1}(\mathcal{O}_S) \cong \mathcal{O}_X$$
hence
$$F^*(\mathcal{O}_X)(X)\cong \mathcal{O}_X(X) \cong B.$$
To people reacting negatively to this, denouncing it as "vandalism": Do exercise II.1.18 in HH and consult the definition of the notion "morphism of schemes" in Chapter II in HH.
