I am attempting Exercise 5.5.7 from this lecture notes. Let $X \subset \mathbb{A}^m$ and $Y \subset \mathbb{A}^n$ be closed subsets and a morphism of varieties $f: X \to Y$, extend $f$ to a morphism of varieties $\overline{f}: \mathbb{A}^m \to \mathbb{A}^n$.
My idea is passing from the category of affine varieties to the category of reduced $k$-algebras of finite type. Firstly note that $\mathcal{O}_{\mathbb{A}^n}(\mathbb{A}^n)=k[x_1,...,x_n]$ and $\mathcal{O}_Y(Y) \cong k[x_1,...,x_n]/I(Y)$ where $I(Y)$ is the associated ideal of $Y$, similarly $\mathcal{O}_X(X) \cong k[y_1,...,y_m]/I(X)$. My goal is constructing a composition $$\mathcal{O}_{\mathbb{A}^n}(\mathbb{A}^n) \to \mathcal{O}_Y(Y) \to \mathcal{O}_X(X) \to \mathcal{O}_{\mathbb{A}^m}(\mathbb{A}^m).$$ I intend to take the first arrow as the quotient map to $I(Y)$ and the second arrow as $f^*$. However I have a trouble for the third arrow. I am also thinking about finding a morphism $h: \mathbb{A}^m \to X$, but I don't think we could do this for every closed set in $\mathbb{A}^m$.
Any help will be appreciated.
You've found one correct portion: composing with the inclusion $Y\to\Bbb A^n$ gets you half of what you need. The other portion is a little trickier: since a map $X\to\Bbb A^n$ is specified by $n$ regular functions in $k[X]=k[\Bbb A^m]/I(X)$, we can lift our $n$ regular functions defining the map from $k[X]$ to $k[\Bbb A^m]$ and use those to define our map $\overline{f}$.