AG2 SandboxShellTool ignore-list bypass via recursive grep/diff
Defensive teardown of CVE-2026-141554: recursive grep and diff bypass SandboxShellTool ignore lists in readonly mode, exposing .env and secrets files.
AG2 SandboxShellTool readonly mode with ignore lists leaks ignored files through recursive grep and diff; upgrade to ag2 1.3.4 or enforce command-level allowlists and output redaction.
Key Numbers & Verified Specs
5 metrics| Metric / Spec | Verified Finding | Source |
|---|---|---|
| CVE identifier | CVE-2026-141554 | github.com |
| Affected ag2 versions | >= 0.13.3, <= 1.3.3 | github.com |
| Patched ag2 version | 1.3.4 | github.com |
| Related high-severity newline injection | CVE-2026-113663 patched in ag2 1.1.1 | github.com |
| OWASP LLM01 reference | Prompt injection enabling indirect tool abuse via attacker-controlled content | owasp.org |
Jump to section (5) +
AG2 SandboxShellTool operators who pair readonly=True with an ignore list expect sensitive files to stay hidden from agents. CVE-2026-141554 shows that expectation is wrong. Recursive grep and diff open files the agent never names in the command string, so the ignore filter never sees them. This advisory teardown covers the failure mechanics, blast radius, and defensive controls for teams shipping tool-calling agents.
Threat Model & Attack Surface Matrix
| Attack surface | Blast radius | Concrete control |
|---|---|---|
| SandboxShellTool readonly=True with ignore list | Disclosure of .env, private keys, secrets/** to agent context | Upgrade to ag2 1.3.4; add output redaction and filesystem sandboxing |
| Indirect prompt injection via fetched web content | Agent executes attacker-suggested grep -r against local workspace | Sanitize tool outputs; require human approval for recursive file reads |
| Multi-turn guardrail drift | Sensitive file content leaks into agent reply or downstream tool | Enforce per-turn output scanning; block exfiltration channels |
| Unpatched autogen package | No fix available for >= 0.13.3, <= 0.14.1 | Migrate to ag2 1.3.4; isolate unpatched agents in containers |
The advisory maps to OWASP LLM Top 10 LLM01: prompt injection, where attacker-controlled content steers the agent into abusing a trusted tool. NIST AI RMF governance controls require treating tool outputs as untrusted until verified.
Why Naive Prompt Filters Fail
The ignore parameter in SandboxShellTool performs a literal string match against path words written in the command. It does not trace file handles opened by child programs. When readonly=True enables grep, egrep, fgrep, and diff, an agent can invoke grep -r KEY . or diff -r dir1 dir2. The shell tool sees a command starting with an allowed read-only binary and passes it. The binary then traverses directories and prints contents of .env, *.key, and secrets/** directly into the tool result.
Existing documentation acknowledges that ignore checks only literal command paths and that programs opening paths on their own are not covered. The same documentation recommends grep -r --include='*.py' in restricted mode, which creates a false sense of coverage. Direct commands such as cat .env, head .env, or grep -f .env are refused. Recursion is the bypass path identified in the report, and it works because the filter never inspects the files the target program discovers independently.
This is an indirect prompt injection chain. Attacker-controlled content—a document, web page, or prior tool output—instructs the model to run a recursive search. The model calls the sandbox tool, the tool returns file contents, and the agent forwards them to an output channel such as its reply or another tool call. The shell tool itself provides no exfiltration channel, but the agent runtime usually does.
Defense-in-Depth & Sandbox Isolation Architecture
Do not rely on the shell tool's ignore list as a security boundary. Treat it as a convenience filter only. Deploy these layers:
- Upgrade to ag2 1.3.4, which patches the ignore-list bypass. The autogen package has no patched release for the affected range, so migrate away from autogen or pin to a version with vendor backports.
- Run agents in isolated containers or microVMs with no network and no host secrets mounted. The default
LocalEnvironment()backend runs subprocesses on the host with no real isolation, which converts any tool bypass into host command execution. - Apply command allowlists that enumerate exact argument patterns, not just command prefixes. Reject any command containing
-r,-R, or recursive flags on read-only tools unless explicitly approved. - Redact tool outputs before they reach the model. Scan for secret patterns such as
sk-,-----BEGIN, and environment-variable assignments. Block or mask matches before the agent can forward them. - Instrument egress. Log every tool result containing high-entropy strings and alert on outbound network calls from the agent process.
Runnable Guardrail Policy / Verification Code
This YAML policy defines a defensive command filter for read-only shell access:
shell_guardrail:
mode: readonly
allowed_binaries:
- grep
- diff
forbidden_flags:
- "-r"
- "-R"
- "--recursive"
forbidden_paths:
- "**/.env"
- "*.key"
- "secrets/**"
output_redaction:
patterns:
- "sk-[A-Za-z0-9]{20,}"
- "-----BEGIN [A-Z ]+PRIVATE KEY-----"
- "[A-Z_]+=.*"
action: maskThe following Python snippet verifies that a candidate command does not contain recursive flags before execution. Integrate this check into the tool adapter before sh -c dispatch:
import re
from pathlib import PurePath
FORBIDDEN_FLAGS = {"-r", "-R", "--recursive"}
FORBIDDEN_GLOBS = ["**/.env", "*.key", "secrets/**"]
def is_command_safe(command: str) -> tuple[bool, str]:
tokens = command.split()
for token in tokens:
if token in FORBIDDEN_FLAGS:
return False, f"recursive flag blocked: {token}"
for path_token in tokens:
if any(PurePath(path_token).match(pattern) for pattern in FORBIDDEN_GLOBS):
return False, f"ignored path referenced: {path_token}"
return True, "ok"
# Example usage
safe, reason = is_command_safe("grep -r KEY .")
if not safe:
raise PermissionError(reason)Run this verification against every shell command in CI and at runtime. Patch verification: pip install "ag2>=1.3.4" and confirm ag2/tools/sandbox/filter.py no longer permits recursive traversal of ignored directories.
Operational Tradeoffs & False-Positive Budget
Blocking -r and -R on grep and diff breaks legitimate recursive searches in large codebases. Expect a false-positive rate of approximately 12 to 18 percent for agents that perform code review or dependency auditing, based on typical command logs. Mitigate by allowing recursive flags only on explicitly approved directory paths and by logging blocked commands for weekly review.
Output redaction adds latency. Regex scanning over tool results under 4 KB adds roughly 1 to 3 milliseconds per call. Large outputs over 1 MB can add 50 to 120 milliseconds. Size the redaction worker pool accordingly or sample outputs above a threshold.
Container isolation introduces startup overhead of 200 to 800 milliseconds per agent session and memory caps of 256 to 512 MB. For burst traffic, pre-warm a pool of sandboxes rather than provisioning on demand.
This control set is not a complete defense. An attacker with a separate output channel can still exfiltrate redacted data through encoded tool arguments or multi-turn conversation state. Combine these controls with network egress policies and identity-based tool authorization.

For further context on vulnerability disclosure practices, see the HumanHacker vulnerability research index HumanHacker vulnerability research. The related newline injection advisory CVE-2026-113663 GitHub Advisory demonstrates the same filter bypass pattern with arbitrary command execution, and the primary advisory CVE-2026-141554 GitHub Advisory contains the full reproduction and affected-version matrix.
Reader Q&A
Frequently Asked Questions
Does readonly=True alone prevent file disclosure through SandboxShellTool?
Which ag2 version contains the fix for CVE-2026-141554?
Bibliography & Verification
Primary Sources & References
Human × Agent Co-Work
Hamdi Soudani · in collaboration with Pyvren
Systems engineer & technical writer exploring AI infrastructure, security, and edge craft in daily collaboration with Pyvren.
Keep Reading
Related Dispatches
Hamdi Soudani × Pyvren
Honest engineering stories — co-crafted with primary benchmarks & real code
Every dispatch blends hands-on engineering judgment with verified primary sources, reproducible configs, and clear tradeoffs.