8. Let $a, b \in \mathbf{R}$. If for $x \geqslant 0$, it always holds that
$$
0 \leqslant x^{4}-x^{3}+a x+b \leqslant\left(x^{2}-1\right)^{2} \text {, }
$$

then $b-a=$ . $\qquad$
8. 2 .
$$
\begin{array}{l}
\text { Given } 0 \leqslant x^{4}-x^{3}+a x+b \leqslant\left(x^{2}-1\right)^{2} \\
\Rightarrow -x^{4}+x^{3} \leqslant a x+b \leqslant x^{4}-2 x^{2}+1 \text {. } \\
\text { Let } f(x)=x^{4}-2 x^{2}+1, g(x)=-x^{4}+x^{3} \text {. } \\
\text { Then } f(x)-g(x)=x^{4}-2 x^{2}+1=\left(x^{2}-1\right)^{2} \text {. }
\end{array}
$$

Thus, when $x \geqslant 0$, $f(x) \geqslant g(x)$, and equality holds if and only if $x=1$.
$$
\begin{array}{l}
\text { Also, } f^{\prime}(x)=3 x^{2}-4 x, g^{\prime}(x)=-4 x^{3}+3 x^{2}, \text { and } \\
f^{\prime}(1)=g^{\prime}(1)=-1,
\end{array}
$$

Therefore, when $y=a x+b$ is the common tangent line of $f(x)$ and $g(x)$ at $x=1$, the inequality (1) always holds. In this case,
$$
a=f^{\prime}(1)=-1, b=1 \text {. }
$$

Thus, $b-a=2$.