5. Given the function $f(x)$ with domain $\left(-\frac{\sqrt{3}}{3}\right.$, $\left.\frac{\sqrt{3}}{3}\right)$, $g(x)=f\left(\frac{\cos x}{2+\sin x}\right)$. Then the domain of the function $g(x)$ is
5. $\left\{x \mid x \in \mathbf{R}\right.$, and $\left.x \neq 2 k \pi \pm \frac{\pi}{6}, k \in \mathbf{Z}\right\}$.

Let $\frac{\cos x}{2+\sin x}=t, \sin \alpha=\frac{1}{\sqrt{1+t^{2}}}$,
$\cos \alpha=\frac{t}{\sqrt{1+t^{2}}}$. Then
$\cos x-t \sin x=2 t$,
$\sin \alpha \cos x-\cos \alpha \sin x=\frac{2 t}{\sqrt{1+t^{2}}}$.
$\therefore \sin (\alpha-x)=\frac{2 t}{\sqrt{1+t^{2}}}$.
$\because|\sin (\alpha-x)| \leqslant 1$,
$\therefore\left|\frac{2 t}{\sqrt{1+t^{2}}}\right| \leqslant 1$.
Solving this, we get
$-\frac{\sqrt{3}}{3} \leqslant t \leqslant \frac{\sqrt{3}}{3}$.
$\because f(x)$'s domain is $\left(-\frac{\sqrt{3}}{3}, \frac{\sqrt{3}}{3}\right)$,
$\therefore t \neq \pm \frac{\sqrt{3}}{3}$.
When $t= \pm \frac{\sqrt{3}}{3}$, $x=2 k \pi \pm \frac{\pi}{6}(k \in \mathbf{Z})$;
When $t \neq \pm \frac{\sqrt{3}}{3}$, $x \neq 2 k \pi \pm \frac{\pi}{6}(k \in \mathbf{Z})$.
$\therefore g(x)$'s domain is
$|x| x \in \mathbf{R}$, and $\left.x \neq 2 k \pi \pm \frac{\pi}{6}, k \in \mathbf{Z}\right\}$