$\def\bbA{\mathbb{A}} \def\spec{\operatorname{Spec}} \def\sO{\mathcal{O}} \def\sA{\mathcal{A}}$Let $k$ be a non-algebraically closed field. Let $X=V(I)\subset\bbA^n_k$ be a classical affine variety (where $I\subset k[x_1,\dots,x_n]$ is an ideal), which is naturally a locally ringed space over $\spec k$ when equipped with the sheaf of regular functions. Denote $\sA(X)=k[x_1,\dots,x_n]/I(X)$ to the $k$-algebra of polynomial functions on $X$. Then we have a containment $$ \tag{1}\label{1} \sA(X)\subset\Gamma(X,\sO_X) $$ which in general is not an equality (for instance, consider $k=\mathbb{R}$, $X$ the real affine line and $\frac{1}{1+x^2}\in\Gamma(X,\sO_X)$). Suppose now that we have another classical affine variety $Y=V(J)\subset\bbA^m_k$ and an isomorphism $\varphi:X\to Y$ of locally ringed spaces over $\spec k$. We then get an induced isomorphism $\varphi^*:\Gamma(Y,\sO_Y)\to\Gamma(X,\sO_X)$ of $k$-algebras, given by precomposition by $\varphi$.
I have two questions:
Does it hold $\varphi^*(\sA(Y))\subset\sA(X)$?
If 1 is false in general, can we always find some isomorphism $\psi:X\to Y$ such that $\psi^*(\sA(Y))\subset\sA(X)$?
(Note that if $k$ were algebraically closed, then 1 holds, for \eqref{1} is an equality on this case.)
I am trying to produce a counterexample for 1 given by some automorphism of the real affine. I am thinking on a map of the form \begin{align*} \rho:\mathbb{R}&\to\mathbb{R}\\ a&\mapsto\frac{f(a)}{1+a^2}, \end{align*} where $f(x)\in\mathbb{R}[x]$. However, I don't know if we can find $f$ so that $\rho$ is bijective and $\rho^{-1}$ is given by a quotient of polynomials.
Put in other words, this post is asking: is the $k$-algebra of polynomials functions $\sA(X)\subset\Gamma(X,\sO_X)$ an invariant of $X$ as a classical affine algebraic variety? (I guess this question is relevant in the field of real algebraic geometry, for instance.)
EDIT: E. Wofsey's counterexample implies that the answer is no.