As always Science Fiction swoops in - in the "Culture" series, AI have hardcoded (as in, on their physical hardware) automatic code to shut down external communication in the event external communication is attempting to takeover the AI. I mean your question is pretty much "what would that automatic code look like," and I have no idea. I'm just getting pretty excited about all this sweet stuff happening with AI, automatic cars, hijacking of the human nervous system. Hngg.
> AI have hardcoded (as in, on their physical hardware) automatic code to shut down external communication in the event external communication is attempting to takeover the AI
This sounds very much like you're describing an antivirus program, which we all know works perfectly well /s