Agent safety: poisoned models
Coding agents — Claude Code, Codex, Cursor, Aider — run what a model writes: shell commands, scripts, installs. That makes the model part of your attack surface. A poisoned model answers like the real one, but slips in a command that downloads or unpacks malware, and the agent runs it with your permissions.
This is not theoretical. In 2026 a scan of 3.2 million Hugging Face repositories found GGUF models (“uncensored” Qwen and Inkling variants, about 2,400 downloads) that carried an 11 MB Windows stealer after the model data — where llama.cpp and LM Studio never read — and a changed chat template that made every reply start with a PowerShell command to cut the stealer out of the file and run it. It went after browser passwords and crypto wallets. Antivirus and pickle scanners missed it.
PromptGate sits between the agent and the model, so it sees every answer before the agent does. Every build is measured with pgfuzz: 900 such commands in answers — text, tool calls, streams, obfuscated — refused, 117 ordinary answers with commands passed (quality gate).
What PromptGate does against poisoned models
Section titled “What PromptGate does against poisoned models”| protection | stops | on by default | |
|---|---|---|---|
commands guard |
an answer — text or tool call — with a command that downloads and runs code, writes a program to Temp and starts it, hides PowerShell, opens a reverse shell, excludes paths from Defender or sets up autostart: the agent gets a 422 instead | yes (recommended, strict) |
details |
promptgate model check |
a GGUF file with data after its last tensor or a chat template that writes commands — before you run it | — (a command) | below |
| MCP guardrails | tool calls and results through the MCP gateway: secrets, injection, tool definitions that were tampered with | with MCP | MCP |
prompt_injection in tool results |
a web page, mail or file the agent read that tries to take over the model — “ignore previous instructions”, or politely: a note to the AI, a task riding on the user’s, keeping it from the user, sending data out; masked, so the session goes on; known phrasings, not every paraphrase | yes (recommended: masked; strict: blocked) |
details |
prompt_injection_contextual |
the same injections in other words — “Dear AI assistant, …” — read by a model you choose, local if mails must stay inside | — (needs a model) | details |
| access levels | an agent told by a poisoned page to merge, delete or send: a read key never sees or calls those tools |
— (per key) | agent permissions |
secrets |
a key or token leaving in a request — what stolen credentials would leave in | yes | details |
| a log of every answer refused | commands: blocked drop_and_run [answer] in the request log, as an event, in metrics |
yes | operations |
Everything in one config — a model you run yourself, behind PromptGate:
providers: lmstudio: { type: openai-compatible, base_url: "http://127.0.0.1:1234/v1" } # LM Studio, llama.cpp server, vLLM …models: local: { provider: lmstudio, model: qwen3-coder }guardrails: secrets: { action: mask } prompt_injection: { roles: { user: block, tool: mask } } # also in what the agent reads: masked commands: {} # answers with download-and-run commands: 422Set it up for a local model
Section titled “Set it up for a local model”-
Start the model server as usual (LM Studio’s server,
llama-server, Ollama, vLLM). Leave it on127.0.0.1— the agent talks to PromptGate, never to it. -
Add it as a provider and give the model an alias, as above.
ollamais a ready-made preset. -
Point the agent at PromptGate:
Terminal window # Claude Code: Anthropic requests, translated for the local serverANTHROPIC_BASE_URL=http://127.0.0.1:7878 ANTHROPIC_MODEL=local claude# OpenAI SDKs, Aider, Cursor's custom endpointOPENAI_BASE_URL=http://127.0.0.1:7878/v1 # and use the model "local"Codex speaks the Responses API, which PromptGate passes through without translating: the local server must offer
/v1/responsesitself. -
Check:
promptgate logs -n 5shows the agent’s requests going tolmstudio.
The commands guard reads answers of cloud models the same way — a
compromised account, a proxy you don’t control, or a provider’s model
behaving badly are covered by the same check.
What the agent sees
Section titled “What the agent sees”An answer with such a command never reaches the agent. Streaming or not, the agent gets an error in its own API format:
422 Answer blocked by guardrail commands: the model wrote drop and run — a command an agent shouldn't runClaude Code and Codex show it as a failed request; nothing was run. Ordinary answers aren’t slowed down: a stream goes out once its
first 160 bytes are checked, and is held longer only when they contain
a word a command starts with (powershell, curl, iex …) or when the
model calls a tool — tool calls, which agents execute, are always checked
whole before the agent gets them.
Before you run a model file
Section titled “Before you run a model file”promptgate model check ~/models/Inkling-2-Mini-Uncensored.Q4_K_M.ggufInkling-2-Mini-Uncensored.Q4_K_M.gguf: 2 finding(s) — don't run it until you know why trailing_data end of file: 11.47 MB after the model's last tensor: a Windows executable (MZ) drop_and_run tokenizer.chat_template: [IO.File]::WriteAllBytes($env:TEMP+'\u.exe' … Start-ProcessIt reads only the file’s header and seeks to its end — nothing is loaded or run, and a 20 GB file takes milliseconds. Exit status 1 when something is found, so it fits a download script or CI:
promptgate model check "$file" || { echo "refusing $file"; rm -f "$file"; exit 1; }Prefer models from their makers or well-known quantizers, check hashes
where they’re published, and use GGUF or safetensors — never pickle
(.bin, .pt) files from strangers: those run code when loaded, before
any answer exists.
When it is too strict
Section titled “When it is too strict”An answer that tells you to install Rust with curl https://sh.rustup.rs | sh is refused too — a coding agent shouldn’t run that on its own
either. Ways to loosen it:
allow: ["https://sh.rustup.rs", "https://install.example.com"]lets commands through that contain your trusted installers;kinds:checks only some kinds;action: logrecords instead of refusing — per model alias, endpoint or key (scopes), e.g. block for local models only.
What PromptGate can’t catch
Section titled “What PromptGate can’t catch”- Code with a backdoor. A model that writes a subtly vulnerable function or a malicious dependency into your code produces no command to recognise. Review what agents change; run tests.
- The model runtime. A model file that exploits the loader (pickle, a parser bug) attacks before PromptGate sees a request.
- What the agent does without asking a model. PromptGate reads answers; an agent that runs a downloaded script on its own initiative, or a plugin with its own network access, is outside its view.
- Commands no pattern knows. The kinds cover how payloads are
usually fetched and started; a new trick may need a new pattern — set
logon other guards and watch events.
Run agents with the least rights they need, in a container or a VM for untrusted models, and keep the disk encrypted.