[proofplan]
Fix the error tolerance and choose an open buffer $V$ whose compact closure lies inside the given neighbourhood $U$. The holomorphic convexity property of the Stein compact $K$ separates each boundary point of $V$ from $K$ by a global holomorphic function, and compactness of $\partial V$ reduces this separation to finitely many functions. Their strict sublevel inequalities define a Runge Stein analytic polyhedron $A$; the connected components of $A$ meeting $K$ lie inside $U$, so the given holomorphic function extends to all of $A$ by zero on the remaining components. Cartan's Runge approximation theorem for Stein pairs, obtained from Cartan's Theorem B, then approximates this extension uniformly on $K$ by restrictions of global holomorphic functions on $X$.
[/proofplan]
[step:Choose a compact buffer inside the neighbourhood of $K$]
Let $\varepsilon > 0$ be fixed. If $K = \varnothing$, the assertion is vacuous, so assume $K \neq \varnothing$.
Since $X$ is a complex manifold, it is locally compact and regular. Since $K$ is compact and $U \subset X$ is open with $K \subset U$, choose an open subset $V \subset X$ such that $K \subset V$ and the closure $\overline V$ in $X$ is compact and satisfies $\overline V \subset U$. Define the boundary of $V$ in $X$ by $\partial V := \overline V \setminus V$.
[/step]
[step:Separate the boundary of the buffer from $K$ by finitely many global holomorphic functions]
For a compact subset $B \subset X$, define its $\mathcal{O}(X)$-hull by
\begin{align*}
\widehat B_{\mathcal{O}(X)}
:=
\{p \in X : |q(p)| \leq \sup_{b \in B} |q(b)| \text{ for every } q \in \mathcal{O}(X)\}.
\end{align*}
By the holomorphic convexity property of Stein compacts in a Stein manifold, $\widehat K_{\mathcal{O}(X)} = K$. Let $y \in \partial V$. Since $K \subset V$ and $\partial V \cap V = \varnothing$, we have $y \notin K$, hence $y \notin \widehat K_{\mathcal{O}(X)}$. Therefore there exists a holomorphic map $h_y : X \to \mathbb{C}$ such that
\begin{align*}
|h_y(y)| > \sup_{\xi \in K} |h_y(\xi)|.
\end{align*}
Define
\begin{align*}
M_y := \sup_{\xi \in K} |h_y(\xi)|,
\qquad
c_y := \frac{M_y + |h_y(y)|}{2}.
\end{align*}
Then $M_y < c_y < |h_y(y)|$. By continuity of the map $|h_y| : X \to [0,\infty)$, there exists an open neighbourhood $N_y \subset X$ of $y$ such that $|h_y(z)| > c_y$ for every $z \in N_y$.
If $\partial V = \varnothing$, set $m := 0$. If $\partial V \neq \varnothing$, the compact set $\partial V$ is covered by the open sets $N_y$ with $y \in \partial V$, so choose points $y_1,\ldots,y_m \in \partial V$ such that
\begin{align*}
\partial V \subset \bigcup_{j=1}^m N_{y_j}.
\end{align*}
For $1 \leq j \leq m$, define $h_j := h_{y_j}$ and $c_j := c_{y_j}$.
[guided]
We need finitely many global holomorphic functions that force a neighbourhood of $K$ to stay away from the boundary of the buffer $V$. The relevant separation property is holomorphic convexity. For a compact subset $B \subset X$, define
\begin{align*}
\widehat B_{\mathcal{O}(X)}
:=
\{p \in X : |q(p)| \leq \sup_{b \in B} |q(b)| \text{ for every } q \in \mathcal{O}(X)\}.
\end{align*}
The hypothesis that $K$ is a Stein compact in the Stein manifold $X$ gives the holomorphic convexity condition $\widehat K_{\mathcal{O}(X)} = K$. Now fix $y \in \partial V$. Since $K \subset V$ while $\partial V \cap V = \varnothing$, the point $y$ does not belong to $K$. Because $K$ equals its $\mathcal{O}(X)$-hull, this means $y \notin \widehat K_{\mathcal{O}(X)}$. By the definition of the hull, there is a holomorphic map $h_y : X \to \mathbb{C}$ such that
\begin{align*}
|h_y(y)| > \sup_{\xi \in K} |h_y(\xi)|.
\end{align*}
Define the two constants
\begin{align*}
M_y := \sup_{\xi \in K} |h_y(\xi)|,
\qquad
c_y := \frac{M_y + |h_y(y)|}{2}.
\end{align*}
The strict inequality above gives $M_y < c_y < |h_y(y)|$. The purpose of $c_y$ is to create a strict threshold: every point of $K$ satisfies $|h_y| \leq M_y < c_y$, while $y$ satisfies $|h_y(y)| > c_y$. Since $|h_y| : X \to [0,\infty)$ is continuous, there is an open neighbourhood $N_y \subset X$ of $y$ such that $|h_y(z)| > c_y$ for every $z \in N_y$.
The set $\partial V$ is compact because it is closed in the compact set $\overline V$. If $\partial V = \varnothing$, no separating functions are needed and we set $m := 0$. If $\partial V \neq \varnothing$, the open cover $\{N_y : y \in \partial V\}$ of $\partial V$ has a finite subcover. Thus there exist points $y_1,\ldots,y_m \in \partial V$ such that
\begin{align*}
\partial V \subset \bigcup_{j=1}^m N_{y_j}.
\end{align*}
For each index $j$ with $1 \leq j \leq m$, define $h_j := h_{y_j}$ and $c_j := c_{y_j}$.
[/guided]
[/step]
[step:Build a Runge Stein analytic polyhedron whose relevant components lie inside $U$]
Define the open subset $A \subset X$ by
\begin{align*}
A :=
\{z \in X : |h_j(z)| < c_j \text{ for every } j \in \{1,\ldots,m\}\},
\end{align*}
with the convention that if $m = 0$, then $A = X$. Since $|h_j(\xi)| \leq M_{y_j} < c_j$ for every $\xi \in K$ and every $j$, we have $K \subset A$. Also $A \cap \partial V = \varnothing$: if $z \in \partial V$, then for some $j$ we have $z \in N_{y_j}$, hence $|h_j(z)| > c_j$, so $z \notin A$.
Let $\Omega \subset A$ be the union of all connected components $C$ of $A$ such that $C \cap K \neq \varnothing$. Since open subsets of complex manifolds are locally path connected, connected components of $A$ are path connected. If such a component $C$ met $X \setminus V$, then a path in $C$ from a point of $C \cap K \subset V$ to a point of $C \setminus V$ would meet $\partial V$, contradicting $C \subset A$ and $A \cap \partial V = \varnothing$. Hence $\Omega \subset V \subset U$.
We next prove that $A$ is Runge in $X$. Let $L \subset A$ be compact and define
\begin{align*}
\widehat L_{\mathcal{O}(X)}
:=
\{p \in X : |q(p)| \leq \sup_{\ell \in L} |q(\ell)| \text{ for every } q \in \mathcal{O}(X)\}.
\end{align*}
Because $X$ is Stein, $\widehat L_{\mathcal{O}(X)}$ is compact by the holomorphic convexity of Stein manifolds. For each $j$, define
\begin{align*}
r_j := \sup_{\ell \in L} |h_j(\ell)|.
\end{align*}
Since $L$ is compact and $L \subset A$, continuity gives $r_j < c_j$. If $p \in \widehat L_{\mathcal{O}(X)}$, then the defining inequality for the hull applied to $q = h_j$ gives $|h_j(p)| \leq r_j < c_j$ for every $j$. Hence $p \in A$, so $\widehat L_{\mathcal{O}(X)} \subset A$. Thus $A$ is a Runge open subset of $X$.
Since $X$ is Stein and $A$ is Runge in $X$, the Runge domain theorem for Stein manifolds implies that $A$ is Stein. Since $\Omega$ is open and closed in $A$, $\Omega$ is also Stein.
[guided]
Define
\begin{align*}
A :=
\{z \in X : |h_j(z)| < c_j \text{ for every } j \in \{1,\ldots,m\}\},
\end{align*}
and if $m = 0$, interpret this condition as empty, so $A = X$. The set $A$ is open because each $h_j : X \to \mathbb{C}$ is continuous and each inequality $|h_j(z)| < c_j$ defines an open preimage.
The set $A$ contains $K$. Indeed, for every $\xi \in K$ and every $j$,
\begin{align*}
|h_j(\xi)| \leq \sup_{\eta \in K} |h_j(\eta)| = M_{y_j} < c_j.
\end{align*}
The set $A$ avoids the boundary $\partial V$. If $z \in \partial V$, then the finite cover of $\partial V$ gives an index $j$ such that $z \in N_{y_j}$. By construction of $N_{y_j}$, this implies $|h_j(z)| > c_j$, so $z$ violates the defining inequality for $A$. Therefore $A \cap \partial V = \varnothing$.
Now define $\Omega \subset A$ to be the union of all connected components $C$ of $A$ satisfying $C \cap K \neq \varnothing$. This is the part of $A$ on which the original function $f$ is relevant. We claim $\Omega \subset U$. Since $\Omega$ is a union of components meeting $K$, it is enough to prove that each such component lies in $V$. Let $C$ be a connected component of $A$ with $C \cap K \neq \varnothing$. Open subsets of complex manifolds are locally path connected, so the component $C$ is path connected. Choose $a \in C \cap K$. Since $K \subset V$, we have $a \in V$. If there were a point $b \in C \setminus V$, a continuous path $\gamma : [0,1] \to C$ with $\gamma(0)=a$ and $\gamma(1)=b$ would pass from $V$ to its complement. Hence $\gamma([0,1])$ would meet $\partial V$. This is impossible because $C \subset A$ and $A \cap \partial V = \varnothing$. Thus $C \subset V$, and therefore $\Omega \subset V \subset U$.
It remains to record the approximation-theoretic property of $A$. Let $L \subset A$ be compact and define its $\mathcal{O}(X)$-hull by
\begin{align*}
\widehat L_{\mathcal{O}(X)}
:=
\{p \in X : |q(p)| \leq \sup_{\ell \in L} |q(\ell)| \text{ for every } q \in \mathcal{O}(X)\}.
\end{align*}
Because $X$ is Stein, compact subsets have compact holomorphic hulls by the holomorphic convexity of Stein manifolds. For each $j$, define
\begin{align*}
r_j := \sup_{\ell \in L} |h_j(\ell)|.
\end{align*}
The compactness of $L$ and the strict containment $L \subset A$ give $r_j < c_j$. If $p \in \widehat L_{\mathcal{O}(X)}$, then applying the defining hull inequality to the particular global holomorphic function $h_j$ gives
\begin{align*}
|h_j(p)| \leq \sup_{\ell \in L} |h_j(\ell)| = r_j < c_j.
\end{align*}
This holds for every $j$, so $p \in A$. Therefore $\widehat L_{\mathcal{O}(X)} \subset A$ for every compact $L \subset A$, which is exactly the Runge condition for $A$ in $X$.
The Runge domain theorem for Stein manifolds applies because $X$ is Stein and $A$ is a Runge open subset of $X$. It follows that $A$ is Stein. Since $\Omega$ is a union of connected components of $A$, it is open and closed in $A$; consequently $\Omega$ is a Stein open-and-closed submanifold of the Stein manifold $A$.
[/guided]
[/step]
[step:Extend the local holomorphic function to the Runge Stein polyhedron]
View the given function as a holomorphic map $f : U \to \mathbb{C}$. Since $\Omega \subset U$, the restriction $f|_{\Omega} : \Omega \to \mathbb{C}$ is holomorphic. Define a map $F : A \to \mathbb{C}$ by
\begin{align*}
F(z) :=
\begin{cases}
f(z), & z \in \Omega,\\
0, & z \in A \setminus \Omega.
\end{cases}
\end{align*}
The sets $\Omega$ and $A \setminus \Omega$ are open in $A$ because $\Omega$ is open and closed in $A$. On $\Omega$, the map $F$ equals the holomorphic map $f|_{\Omega}$; on $A \setminus \Omega$, it equals the zero holomorphic map $A \setminus \Omega \to \mathbb{C}$. Holomorphicity is local, hence $F \in \mathcal{O}(A)$. Since $K \subset \Omega$, we have $F|_K = f|_K$.
[/step]
[step:Approximate the extension on $K$ by a global holomorphic function]
Define the restriction map
\begin{align*}
\rho_{X,A} : \mathcal{O}(X) &\to \mathcal{O}(A)\\
q &\mapsto q|_A.
\end{align*}
By Cartan's Runge approximation theorem for Stein pairs, a consequence of Cartan's Theorem B applied through the Cousin I splitting argument, the image of $\rho_{X,A}$ is dense in $\mathcal{O}(A)$ for the compact-open topology whenever $X$ is Stein and $A \subset X$ is Runge and Stein. These hypotheses hold by the preceding step.
Apply this density statement to the compact set $K \subset A$, the function $F \in \mathcal{O}(A)$, and the tolerance $\varepsilon > 0$. There exists $g \in \mathcal{O}(X)$ such that
\begin{align*}
\sup_{x \in K} |F(x) - g(x)| < \varepsilon.
\end{align*}
Since $F|_K = f|_K$, this gives
\begin{align*}
\sup_{x \in K} |f(x) - g(x)| < \varepsilon.
\end{align*}
This proves the desired approximation.
[guided]
Define the restriction map
\begin{align*}
\rho_{X,A} : \mathcal{O}(X) &\to \mathcal{O}(A)\\
q &\mapsto q|_A.
\end{align*}
We now use the analytic input of the proof: Cartan's Runge approximation theorem for Stein pairs. This theorem says that if $X$ is Stein and $A \subset X$ is a Runge Stein open subset, then the image of $\rho_{X,A}$ is dense in $\mathcal{O}(A)$ for the compact-open topology. The theorem is proved from Cartan's Theorem B by solving the Cousin I splitting problem on Stein covers; the vanishing of the relevant first cohomology group removes the obstruction to patching local holomorphic corrections.
We verify the hypotheses before applying it. The manifold $X$ is Stein by assumption. The set $A$ is Runge in $X$ because every compact $L \subset A$ has $\widehat L_{\mathcal{O}(X)} \subset A$, as proved above. The same step also proved that $A$ is Stein by the Runge domain theorem for Stein manifolds. Therefore Cartan's Runge approximation theorem applies to the pair $A \subset X$.
The compact-open topology on $\mathcal{O}(A)$ is controlled by seminorms of the form
\begin{align*}
p_L(\varphi) := \sup_{z \in L} |\varphi(z)|,
\end{align*}
where $L \subset A$ is compact and $\varphi \in \mathcal{O}(A)$. We apply density with $L = K$, with the holomorphic function $F \in \mathcal{O}(A)$, and with the prescribed tolerance $\varepsilon > 0$. Thus there exists $g \in \mathcal{O}(X)$ such that
\begin{align*}
\sup_{x \in K} |F(x) - g(x)| < \varepsilon.
\end{align*}
The extension $F$ was constructed so that $F(x)=f(x)$ for every $x \in K$, because $K \subset \Omega$. Substituting this equality into the preceding estimate gives
\begin{align*}
\sup_{x \in K} |f(x) - g(x)| < \varepsilon.
\end{align*}
This is exactly the approximation required by the theorem.
[/guided]
[/step]