A former chief executive of Google has warned about the “extreme risk” from terrorists or rogue states using artificial intelligence (AI).