4. Let $x \in\left(-\frac{1}{2}, 0\right)$, then $a_{1}=\cos (\sin x \pi)$, $a_{2}=\sin (\cos x \pi), a_{3}=\cos (x+1) \pi$ have the following relationship ( ).
(A) $a_{3}<a_{2}<a_{1}$
(B) $a_{1}<a_{3}<a_{2}$
(C) $a_{3}<a_{1}<a_{2}$
(D) $a_{2}<a_{3}<a_{1}$
4. (A).

Let $y=-x$, then $y \in\left(0, \frac{1}{2}\right)$, and $a_{1}=$ $\cos (\sin y \pi), a_{2}=\sin (\cos y \pi), a_{3}=\cos (1-y) \pi<0$.
Since $\sin y \pi+\cos y \pi$
$$
=\sqrt{2} \sin \left(y \pi+\frac{\pi}{4}\right) \leqslant \sqrt{2}<\frac{\pi}{2},
$$

therefore, $0<\cos y \pi<\frac{\pi}{2}-\sin y \pi<\frac{\pi}{2}$.
Thus, $0<\sin (\cos y \pi)<\cos (\sin y \pi)$.