5. For any $x \in\left[-\frac{\pi}{6}, \frac{\pi}{2}\right]$, the inequality
$$
\sin ^{2} x+a \sin x+a+3 \geqslant 0
$$

always holds. Then the range of the real number $a$ is $\qquad$
5. $a \geqslant-2$.

Let $f(x)=\sin ^{2} x+a \sin x+a+3$, then
$$
f(x)=\left(\sin x+\frac{a}{2}\right)^{2}+a+3-\frac{a^{2}}{4} \geqslant 0 .
$$

Since $x \in\left[-\frac{\pi}{6}, \frac{\pi}{2}\right]$, therefore, $\sin x \in\left[-\frac{1}{2}, 1\right]$.
Let $t=\sin x$, then $-\frac{1}{2} \leqslant t \leqslant 1$.
$$
\text { Let } g(t)=\left(t+\frac{a}{2}\right)^{2}+3+a-\frac{a^{2}}{4} \text {. }
$$

We need to find all $a$ such that
$$
g(t)=\left(t+\frac{a}{2}\right)^{2}-\frac{a^{2}}{4}+a+3
$$

is greater than or equal to 0 on $\left[-\frac{1}{2}, 1\right]$, which is equivalent to
$$
\begin{array}{l}
\left\{\begin{array} { l } 
{ - \frac { a } { 2 } \leq 1, \\
g(1) \geqslant 0
\end{array}\right.\right.\right. \\
\Leftrightarrow\left\{\begin{array} { l } 
{ a \geq -2, } \\
{ a \geqslant - \frac { 13 } { 2 } }
\end{array} \text { or } \left\{\begin{array} { l } 
{ - 2 \leqslant a \leqslant 1, } \\
{ 6 \geqslant a \geqslant - 2 }
\end{array} \text { or } \left\{\begin{array}{l}
a > 1 \text { or } -2 \leqslant a \leqslant 1 \Leftrightarrow a \geqslant -2 .
\end{array}
$$