4. If the equation $\sqrt{a x^{2}+a x+2}=a x+2$ has exactly one real root, then the range of the real number $a$ is
4. $\{-8\} \cup[1,+\infty)$.

If $a x+20$, then the original equation is equivalent to
$$
\left(a^{2}-a\right) x^{2}+3 a x+2=0,
$$

The above equation has only 1 real solution, which can be divided into the following three cases.
(i) $a^{2}-a=0$, in this case, it is verified that $a=1$ meets the requirement.
(ii) $a^{2}-a \neq 0$, the equation has two equal real roots, i.e., $\Delta=(3 a)^{2}-4 \times 2 \times\left(a^{2}-a\right)=0$, solving for $a=-8$, which is verified to meet the requirement.
(iii) $a^{2}-a \neq 0$, the equation has two distinct real roots $x_{1}, x_{2}\left(x_{1}<1$. In summary, $a=-8$ or $a \geqslant 1$.