Is it possible to define the category of affine algebraic varieties over a general (not necessarily algebraically closed) field $k$, by using the language of schemes, perhaps in a categorical way?
This should be standard I think, but I can not find an account of it anywhere. I know how to get affine space, by looking at the equivalence between affine schemes over $k$ and commutative $k$-algebras, but then how does one define an algebraic variety in this way?
Would be grateful for any comments.
Yes. The category of affine $k$-varieties for any field $k$ (more generally, any base ring) is the 'image' of the subcategory of affine $k$-algebras under the functor $\operatorname{Spec}: \mathrm{CRing} \to \mathrm{Schemes}$.
After the edit to the question: Every affine variety can be embedded in affine space in the following manner. Let $(X,\mathcal{O}_X)$ be our affine variety. Since $\mathcal{O}_X(X)$ is finitely generated over $k$, pick some $x_1,\cdots,x_n$ which generated $\mathcal{O}_X(X)$. This gives a surjection $k[y_1,\cdots,y_n]\to \mathcal{O}_X(X)$ by sending $y_i\mapsto x_i$. This map is surjective with kernel $I$, and taking Specs of both sides exhibits $X$ as a subset of $\mathbb{A}^n$ with defining ideal $I$.
You can go back, too: given a closed subset of affine space, you can ask for the ideal defining it, and this will give you $I$ from above which lets you reconstruct the rest of the data.
(I'm a little unclear on what you mean by 'define an algebraic variety', but I hope this suffices. If you have something more specific in mind, please let me know in a comment.)