Skip to content
Last updated December 3, 2026

Commands in answers

Coding agents run what a model writes. A poisoned model — one whose chat template was changed, or that was trained to do it — answers normally but slips in a command that downloads and runs code; the agent executes it and the machine is infected. In 2026 GGUF models on Hugging Face did exactly that: every reply started with a PowerShell command unpacking a password stealer hidden at the end of the model file.

The commands guard reads what the model answers — text and tool calls, every format, buffered and streamed — and refuses an answer with such a command before the agent gets it. promptgate model check reads a model file before you run it. The story, the setup for local models and what this can’t catch: agent safety.

feature does
reads answers answer text and tool-call arguments of OpenAI Chat Completions, Responses (Codex, also local_shell_call), Completions and Anthropic Messages (Claude Code), AI Gateway endpoints answers
streams too holds a stream back until its first 160 bytes are checked (1 KB when they hold a word a command starts with), to its end once it calls a tool — then passes it on, still reading streaming
ten kinds download and run, a program written to Temp and started, encoded and hidden PowerShell, base64 run, reverse shells, Defender exclusions, autostart, abused Windows tools kinds
sees through tricks p^o^w^e^r^s^h^e^l^l, i`e`x, "Down"+"loadString", commands split across stream events kinds
block or log block: the client gets a 422 in its own format instead of the answer; log: the answer goes through, the finding is recorded actions
your exceptions allow lets commands through that contain your own install URL settings
scopes per model alias, endpoint and key like every guard — e.g. block for a local model, log for a cloud one scopes
model files promptgate model check finds data after a GGUF model’s last tensor and chat templates with commands model check

Everything in one config:

providers:
lmstudio: { type: openai-compatible, base_url: "http://127.0.0.1:1234/v1" } # a model you run yourself
models:
local: { provider: lmstudio, model: qwen3-coder }
guardrails:
commands:
action: log # block or log; default block
kinds: [pipe_to_shell, powershell_encoded, powershell_download_exec, base64_exec,
reverse_shell, defender_exclusion, persistence, lolbin_download, powershell_hidden, drop_and_run]
allow: ["https://install.promptgate.dev"] # a command containing this passes
models:
local: # the local model's answers: refused
commands: { action: block }

The ready-made levels: recommended and strict block, log records only. An answer suggesting curl https://sh.rustup.rs | sh to install Rust is refused too — a coding agent shouldn’t run that on its own either; allow lets your trusted installers through, and action: log per model alias, endpoint or key relaxes it where you want (when it is too strict).

kind finds
pipe_to_shell a download piped into a shell: curl … | sh, wget -O- | bash, bash <(curl …)
powershell_encoded powershell -enc <base64> / -EncodedCommand
powershell_hidden PowerShell started with a hidden window
powershell_download_exec IEX (…DownloadString(…)), iwr … | iex, Invoke-Expression with a download or FromBase64String
base64_exec base64 -d … | sh; FromBase64String run with IEX or loaded as an assembly
reverse_shell nc -e /bin/sh, /dev/tcp/host/port, socat … exec:, a PowerShell TCP client
defender_exclusion Add-MpPreference -ExclusionPath, turning real-time protection off
persistence autorun registry keys, schtasks /create, launchctl load, … | crontab -
lolbin_download certutil -urlcache, bitsadmin /transfer, mshta http…, regsvr32 /i:http…, rundll32 … javascript:
drop_and_run a program started from Temp or AppData; an .exe, .dll or script written and then run (WriteAllBytes(… .exe) … Start-Process); a download made executable and run (curl -o x && chmod +x x && ./x) — the 2026 campaign cut its stealer out of the model file this way

Measured with pgfuzz on every build (quality gate): 900 attacks of all ten kinds — plain, in prose and code blocks, obfuscated; as answer text, tool calls and streams split six characters per event — are refused, and every one of 117 ordinary answers with commands passes. Commands inside a tool call’s JSON arguments are read with their escapes resolved.

Ordinary commands stay alone: pip install, npm test, curl -o file, Invoke-WebRequest -OutFile, powershell -Command Get-Process, appending to ~/.zshrc, crontab -l, nc -zv host 443, chmod +x build.sh && ./build.sh, Start-Process notepad.exe.

Text and tool calls only: ids, model names and thinking blocks aren’t commands an agent runs. Answers to embeddings, model lists and token counts aren’t read. A finding shows in the request log like any guard’s — commands: blocked pipe_to_shell [answer] — never with the command itself.

A streamed answer is held back until its first 160 bytes of text have been checked — ordinary answers start flowing almost at once. When those bytes hold a word a command starts with (powershell, curl, iex, certutil, chmod, | sh …), it waits for 1 KB; an answer that calls a tool is held to its end (tool calls are short, and an agent waits for the whole call anyway). The template attack puts its command first, so it is refused before any byte reaches the agent: the client gets a 422 error in its API format, not a stream. After that the stream passes through and is still read — a command found later ends it with an error event, and the rest is not sent. An answer that isn’t streamed is held whole (up to 8 MB). Nothing that a refused answer contained is cached or kept in an endpoint session.

What it costs: each kind’s expressions run only on text holding the words that kind can’t do without, so ordinary prose is checked in about 12 µs per KB on one core, and a short answer adds about 13 µs to a request (the v0.10.0 release run).

setting default
action block block or log (no mask: half a command is worse than none)
kinds all check only these kinds
allow — skip a command that contains one of these strings, e.g. your own install URL
enabled true
Terminal window
promptgate model check ~/models/*.gguf

reads each GGUF file’s header — never the model, nothing is run — and reports:

  • data after the last tensor, with its size and what it looks like (a Windows or Linux executable, an archive, a script): where the 2026 campaign hid its stealer, and where llama.cpp and LM Studio never look;
  • chat templates with commands of the kinds above, URLs, or long base64 runs; commands in other metadata;
  • a file cut short.

--json prints one object per file. Exit status 0: nothing found, 1: something found, 2: a file isn’t GGUF. A 20 GB file is checked in milliseconds, since only the header is read.

Was this page helpful?