Skip to content
Last updated December 3, 2026

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: 422
  1. Start the model server as usual (LM Studio’s server, llama-server, Ollama, vLLM). Leave it on 127.0.0.1 — the agent talks to PromptGate, never to it.

  2. Add it as a provider and give the model an alias, as above. ollama is a ready-made preset.

  3. Point the agent at PromptGate:

    Terminal window
    # Claude Code: Anthropic requests, translated for the local server
    ANTHROPIC_BASE_URL=http://127.0.0.1:7878 ANTHROPIC_MODEL=local claude
    # OpenAI SDKs, Aider, Cursor's custom endpoint
    OPENAI_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/responses itself.

  4. Check: promptgate logs -n 5 shows the agent’s requests going to lmstudio.

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.

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 run

Claude 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.

Terminal window
promptgate model check ~/models/Inkling-2-Mini-Uncensored.Q4_K_M.gguf
Inkling-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-Process

It 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:

Terminal window
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.

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: log records instead of refusing — per model alias, endpoint or key (scopes), e.g. block for local models only.
  • 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 log on 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.

Was this page helpful?