Let $A$ be a compact subset of $\mathbb{R}^{n}$ and let $B$ be an open set containing $A$. Prove that there exists a $C^{\infty}$ function $h$ on $\mathbb{R}^{n}$ such that $h=1$ on $A, h=0$ outside $B$, and $0 \leq h \leq 1$ in $B-A$.
I have an idea:
Let $$ \rho(x)= \begin{cases}0, & \text { if }|x| \geq 1 \\ c \exp \left(\frac{1}{|x|^{2}-1}\right), & \text { if }|x|<1\end{cases} $$ where $c$ is a constant such that $\int\limits_{\mathbb{R}} \rho(x) d x=1$, and $|x|=\left(\sum\limits_{i=1}^{n} x_{1}^{2}\right)^{1 / 2}$. Take $$ h(x)=\varepsilon^{-\pi} \int\limits_{G} \rho\left(\frac{x-y}{\varepsilon}\right) d y $$ where $G$ is a bounded open set, $A \subset G \subset \bar{G} \subset B$, and $\varepsilon>0$ sufficiently small.