8. Given that the function $f(x)$ is a decreasing function defined on $(-\infty, 3]$, and for $x \in \mathbf{R}$,
$$
f\left(a^{2}-\sin x\right) \leqslant f\left(a+1+\cos ^{2} x\right)
$$

always holds. Then the range of real number $a$ is $\qquad$
8. $\left[-\sqrt{2}, \frac{1-\sqrt{10}}{2}\right]$.

From the given, we have $a+1+\cos ^{2} x \leqslant a^{2}-\sin x \leqslant 3$ for $x \in \mathbf{R}$, which means
$$
\left\{\begin{array}{l}
a^{2} \leqslant 3+\sin x, \\
a^{2}-a \geqslant 1+\cos ^{2} x+\sin x
\end{array}\right.
$$

for $x \in \mathbf{R}$.
If $a^{2} \leqslant 3+\sin x$ for $x \in \mathbf{R}$, then we have
$$
a^{2} \leqslant(3+\sin x)_{\min }=2 \text {. }
$$

Solving this, we get $-\sqrt{2} \leqslant a \leqslant \sqrt{2}$.
If $a^{2}-a \geqslant 1+\cos ^{2} x+\sin x=2+\sin x-\sin ^{2} x$
$$
=-\left(\sin x-\frac{1}{2}\right)^{2}+\frac{9}{4}
$$

for $x \in \mathbf{R}$, then we have
$$
a^{2}-a \geqslant\left[-\left(\sin x-\frac{1}{2}\right)^{2}+\frac{9}{4}\right] \max =\frac{9}{4} \text {. }
$$

Solving this, we get $a \leqslant \frac{1-\sqrt{10}}{2}$ or $a \geqslant \frac{1+\sqrt{10}}{2}$.
Therefore, the range of real number $a$ is $\left[-\sqrt{2}, \frac{1-\sqrt{10}}{2}\right]$.