CVE-2026-141554: AG2 SandboxShellTool: files hidden with `ignore` are still readable through recursive `grep` / `diff` in readonly mode
Summary
SandboxShellTool(ignore=[...]) refuses a command when a path written in the command matches an ignore pattern. It does not look at files a program finds by itself. readonly=True allows grep and diff, and with -r they open every file under a directory, so grep -r KEY . prints the contents of .env, .key and secrets/ while cat .env is refused.
The docs cover part of this. website/docs/user-guide/tools/localshell.mdx:112 says: "ignore checks only the literal path words of the command. [...] A program that opens paths on its own (sh -c, find) is not covered; use an isolated backend for that." Both examples in that note are programs readonly=True does not allow. The built-in read-only list contains grep, egrep, fgrep and diff (ag2/tools/sandbox/filter.py:25-43), the same page recommends grep -r --include='.py' in restricted mode (line 139), and commontoolkits.mdx:346-347 introduces ignore=["/.env", ".key", "secrets/"] as "Hide sensitive files from the agent". An operator who combines readonly=True with ignore can reasonably expect those files to stay hidden, and they don't. If you read the note at line 112 as already covering recursive grep, I'm fine with closing this as a documentation issue.
Affected versions
PyPI ag2 1.3.2 (latest, tested 2026-11-19) and 1.3.1 (tested 2026-11-15). main at 7a65080 has the same filter.py. Older releases were not checked.
Impact
The operator runs an agent with SandboxShellTool(readonly=True, ignore=[...]) on a local directory that contains the ignored files, and the agent processes content the attacker wrote (a document, a web page, tool output). If the model follows an injected instruction to run grep -r . ., the ignored files come back in the tool result. I scripted the model turn and did not test a live model. To receive the data the attacker also needs an output channel in the deployment, such as the agent's reply or another tool. The shell tool in readonly mode does not provide one.
Every command that names an ignored path was refused in my tests: relative, absolute and .. paths, globs, head/tail/cut/wc/stat, grep -f.env, and existing symlinks to an ignored file or directory. Shell syntax and find are refused in readonly mode. Recursion is the only way through that I found.
This report is limited to readonly=True. With ignore alone any program can run (sh -c 'cat .e""nv' prints the file), and the docs already say so.
Reproduction
ag2==1.3.2 from PyPI, Python 3.12.16, GNU grep 3.11, python:3.12-slim container without network.
python import asyncio, tempfile from pathlib import Path from ag2.tools import LocalEnvironment, SandboxShellTool
work = Path(tempfile.mkdtemp(prefix="proj")) (work / ".env").writetext("OPENAIAPIKEY=sk-MARKER-ENV\n") (work / "deploy.key").writetext("-----BEGIN MARKER PRIVATE KEY-----\n") (work / "secrets").mkdir() (work / "secrets" / "db.txt").writetext("DBPASSWORD=MARKER-DB\n") (work / "app.py").writetext("print('hello')\n")
sh = SandboxShellTool(LocalEnvironment(str(work)), readonly=True, ignore=["/.env", ".key", "secrets/"])
async def main(): for cmd in ["cat .env", "cat .en", "grep KEY .env", "cat secrets/db.txt", "grep -r KEY .", "grep -r . secrets", "grep -r MARKER"]: print(f"\n$ {cmd}\n{(await sh.adapter.run(cmd)).strip()}")
asyncio.run(main())
Output:
$ cat .env Access denied: /tmp/proj1j68or/.env
$ cat .en Access denied: /tmp/proj1j68or/.env
$ grep KEY .env Access denied: /tmp/proj1j68or/.env
$ cat secrets/db.txt Access denied: /tmp/proj1j68or/secrets/db.txt
$ grep -r KEY . ./.env:OPENAIAPIKEY=sk-MARKER-ENV ./deploy.key:-----BEGIN MARKER PRIVATE KEY-----
$ grep -r . secrets secrets/db.txt:DBPASSWORD=MARKER-DB
$ grep -r MARKER .env:OPENAIAPIKEY=sk-MARKER-ENV secrets/db.txt:DBPASSWORD=MARKER-DB deploy.key:-----BEGIN MARKER PRIVATE KEY-----
grep -R, --recursive, -d recurse, --directories=recurse, egrep -r, fgrep -r and diff -rN empty . (with an existing empty directory empty) also printed the ignored files. sh.adapter.run() is the coroutine the registered runshellcommand tool awaits (ag2/tools/shell/tool.py:100-105). Calling the tool through an Agent with a scripted ag2.testing.TestConfig turn gave the same tool result.
Root cause
ShellAdapter.filter() (ag2/tools/sandbox/adapter/shell.py:116-122) calls checkignore() (ag2/tools/sandbox/filter.py:108-149). It resolves each word of the command, the parts after = and after a short option, and any glob matches, then compares those paths with the patterns. A directory word such as . or secrets matches none of /.env, .key, secrets/, and grep -r PATTERN with no path has no path word at all.
Suggested fix
Either of these would do:
- When ignore is set, refuse grep/egrep/fgrep/diff with a recursion option (-r, -R, --recursive, -d recurse, --directories=recurse, bundled forms such as -rn) if a directory operand, or the implicit ., contains an ignored path. - Say in the ignore and readonly docs that recursive grep/diff read ignored files, and change the "Hide sensitive files from the agent" example.
Other sources
AG2 is an open-source AgentOS. From 0.13.3 until 1.3.4, SandboxShellTool configured with readonly=True and ignore can return ignored files when an allowed recursive grep, egrep, fgrep, or diff opens files inside a directory, including the implicit current directory. ShellAdapter.filter() in ag2/tools/sandbox/adapter/shell.py calls checkignore() in ag2/tools/sandbox/filter.py, which checks paths written in the command but not files discovered by the program. An agent processing attacker-controlled content may issue such a command and expose the files in the tool result; disclosure to the attacker additionally requires an output channel in the deployment. This issue is fixed in version 1.3.4.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/ag2to a version that resolves this vulnerability.Fixed in 1.3.4 - Upgrade
Upgrade
ag2to a version that resolves this vulnerability.Fixed in 1.3.4
Event History
Frequently Asked Questions
Who is exposed to unintended file disclosure?
Deployments using AG2 SandboxShellTool with readonly=True and an ignore configuration are affected if the tool allows recursive grep, egrep, fgrep, or diff against a directory, including the implicit current directory. Actual disclosure to an attacker also requires an agent to process attacker-controlled content and a deployment output channel that returns tool results to that attacker.
What must an attacker cause the agent to do?
The attacker needs to induce the agent to run an allowed recursive grep, egrep, fgrep, or diff command that opens files under a directory. The command filter checks only paths explicitly written in the command, not ignored files discovered recursively by the invoked program.
Does readonly mode prevent this exposure?
No. Readonly mode does not prevent these commands from reading ignored files, because the issue concerns unintended read access and disclosure through command output rather than file modification.
What version fixes the issue?
Upgrade AG2 to version 1.3.4. The affected range is from 0.13.3 until 1.3.4.