12. Given $x, y, z \in \mathbf{Z}$, and
$$
x+y+z=3, x^{3}+y^{3}+z^{3}=3 \text {. }
$$

Then $x^{2}+y^{2}+z^{2}=$ $\qquad$
12.3 or 57.

From $x+y=3-z, x^{3}+y^{3}=3-z^{3}$, we get $xy=\frac{8-9z+3z^{2}}{3-z}$.
Thus, $x, y$ are the integer roots of the equation about $t$:
$$
t^{2}-(3-z)t+\frac{8-9z+3z^{2}}{3-z}=0
$$

Then, $\Delta=(3-z)^{2}-4 \cdot \frac{8-9z+3z^{2}}{3-z} \\
=(z-1)^{2}\left(1+\frac{8}{z-3}\right)$
must be a perfect square.
Therefore, $z=1,4,-5$.
When $z=1$, $(x, y, z)=(1,1,1)$;
When $z=4$,
$(x, y, z)=(-5,4,4),(4,-5,4)$;
When $z=-5$, $(x, y, z)=(4,4,-5)$.
In summary, $x^{2}+y^{2}+z^{2}=3$ or 57.