Technically, yes, an AI program can write out malicious code. The recent interest and advances in AI technology have sparked debate on the safety of machine intelligence. The fact that ChatGPT has been used to craft malware has also made headlines. Safeguards are constantly being improved to prevent AI from creating malicious code. This ensures that the possibility is avoided.