Is it written “chissà” or “chi sa”?

Both forms are correct but have two different meanings.
When you want to indicate uncertainty about the content of the sentence you use the form chissà, written all attached and with the emphasis on the “a”.

Chissà is an adverbial phrase that indicates uncertainty or hope and is also used in other cases with the meaning of “maybe”.

Chissà a cosa stava pensando quando a preso quella decisione.

Oggi ha piovuto tutto il giorno. Chissà se domani farà una bella giornata.

Chissà se in futuro riuscirò a raggiungere tutti i miei obiettivi.

The form chi sa was widespread in the past. The italian writer Giovanni Verga was the first to use the all attached form “chissà”that since that time has established itself as correct in contemporary Italian. Chi sa used as an expression of uncertainty is no longer widespread.

Today the form chi sa, written detached and without the accent, is used in sentences where “chi” is relative pronoun and “sa” is the third person of the verb sapere know.

Chi sa come funziona il computer ci dia una mano.

Chissà o chi sa?