The most general result is - I believe - Schmüdgen's Positivstellensatz, which applies to all compact basic semi-algebraic sets. These are the sets which are described by a finite set of polynomial inequalities. The theorem says that every (strictly) positive polynomial function on a compact basic semi-algebraic set is obtained by addition and multiplication from sums of squares and the defining polynomials of the semi-algebraic set.
Hence, if your set is given by polynomial equalities then it is really a sum of squares in the algebra of functions on the real-algebraic variety.
Konrad Schmüdgen, The $K$-moment problem for compact semi-algebraic sets, Math. Ann. 289 (1991), no. 2, 203–206.