Let $M$ be a smooth manifold, $O\subseteq M$ an open subset and $B\subseteq M$ a closed subset, such that $closure(O)\subseteq interior(B)$
I think there must exist a smooth function $f\colon M\rightarrow \mathbb{R}$ such that $0\le f\le 1$, $f|_{M-B}\equiv 0$ and $f|_O\equiv 1$, but was not able to find a reference in the general case. (There are many references if $B$ is compact.)
Can someone please point me in the right direction?
One reference was supplied by John in a comment, with a correction by Jack Lee:
Note that you could just as well consider the disjoint closed sets $\overline{O}$ and $\overline{M\setminus B}$, since the level sets of a continuous function are closed. That is, you are asking for a smooth function separating two disjoint closed sets. The search for "smooth Urysohn lemma" and "disjoint closed sets" brings up a few additional results, such as Lemma 1.3.2 in Manifold Theory by Peter Petersen.