# CVE-2026-113663: AG2: Newline injection in SandboxShellTool bypasses allowed=\[...\] and readonly=True, enabling arbitrary command execution

- **Severity:** HIGH 8.8
- **CVSS:** 8.8 (v3.1, GitHub) `CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Network; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Remote, login needed
- **EPSS:** 0.63% (percentile 45, 2026-11-28)
- **CWE:** CWE-78, CWE-184
- **Aliases:** GHSA-2h4w-29cv-2cmv
- **Published:** 2026-11-10T15:57:17.000Z
- **Modified:** 2026-11-10T15:57:19.000Z

## Who should check

- Projects that depend on PyPI package ag2 (\>= 0.13.2, \< 1.1.1)
- Projects that depend on PyPI package autogen (\>= 0.13.2, \<= 0.14.1)

## Description

\#\#\# Summary
SandboxShellTool's restricted modes — allowed=\[...\] (explicit command allowlist) and readonly=True (implicit READONLY\_COMMANDS allowlist) — can both be bypassed by embedding a newline character inside the command string. The filter only inspects a single-line set of shell metacharacters, but execution runs the raw string through \`sh -c\`, where a shell treats an embedded newline exactly like a \`;\` statement separator. An agent (or content that steers the agent, e.g. via prompt injection) can therefore run arbitrary shell commands even when the tool was configured to allow only a specific command prefix or only read-only commands. With the default LocalEnvironment() backend this is a real host subprocess (its own docstring: "Commands run via subprocess on the host, so there is no real isolation"), not an isolated container, so this is full host command execution, not merely an escape from an already-sandboxed environment.

\#\#\# Details
Both restricted modes are enforced by \`ShellAdapter.\_filter()\` in \`ag2/tools/sandbox/adapter/shell.py\`:

\`\`\`python
def \_filter(self, command: str) -\> str \| None:
    if self.\_allowed is not None:
        if not any(matches(p, command) for p in self.\_allowed):
            return f"Command not allowed: {command!r}"
        if contains\_shell\_operator(command):
            return f"Command not allowed (shell operators are not permitted in restricted mode): {command!r}"
    ...
\`\`\`

\`readonly=True\` reuses this exact same branch: \`SandboxShellTool.\_\_init\_\_\` / \`ShellAdapter.\_\_init\_\_\` sets \`self.\_allowed = list(READONLY\_COMMANDS)\` when \`readonly\` is set and no explicit \`allowed\` is given, so both modes share one filter and one bypass.

\`contains\_shell\_operator()\` in \`ag2/tools/sandbox/filter.py\` checks the command against:

\`\`\`python
\_SHELL\_OPERATORS: tuple\[str, ...\] = ("\>", "\>\>", "\|", ";", "&&", "\|\|", "\`", "$(")
\`\`\`

This tuple has no entry for \`\\n\` (or \`\\r\`). \`matches()\` only checks that the command starts with an allowed prefix followed by a space or end-of-string; it never inspects the remainder of the string. Execution is:

\`\`\`python
argv = \["sh", "-c", command\]
...
return await sandbox.exec(argv, env=self.\_env, timeout=self.\_timeout)
\`\`\`

A POSIX shell splits \`sh -c "\<line1\>\\n\<line2\>"\` into two sequential statements, the same as if they were separated by \`;\`. So a command such as \`"cat allowed\_file.txt\\nrm -rf /anything"\`:

1. Passes \`matches("cat", command)\` — the string starts with \`"cat "\`.
2. 2. Passes \`contains\_shell\_operator(command)\` — \`\\n\` is not a recognized operator.
3. 3. Reaches \`sh -c "cat allowed\_file.txt\\nrm -rf /anything"\`, which runs both statements.
\#\#\# Proof of Concept
Verified directly against the current \`main\` branch (github.com/ag2ai/ag2, commit a05ff1cb6ff4955ef252a4e0d4a27d3a32ad57f0, cloned 2026-09-21), by importing the real \`ag2/tools/sandbox/filter.py\` module (stdlib-only, no other AG2 dependencies needed) and reproducing \`ShellAdapter.\_filter()\`'s allowlist branch verbatim:

\`\`\`
=== allowed=\['cat'\] ===
'cat /etc/passwd; rm -rf /tmp/x'   -\> Command not allowed (shell operators are not permitted in restricted mode): ...
'cat /etc/passwd && rm -rf /tmp/x' -\> Command not allowed (shell operators are not permitted in restricted mode): ...
'cat /etc/passwd \| rm -rf /tmp/x'  -\> Command not allowed (shell operators are not permitted in restricted mode): ...
'cat /etc/passwd\\nrm -rf /tmp/x'   -\> None   \<-- BYPASS: newline variant is NOT rejected

=== readonly=True (uses READONLY\_COMMANDS as the allowed list) ===
'echo hi\\nid'                      -\> None   \<-- BYPASS in readonly mode too

=== sh -c really treats the embedded newline as a second statement (mirrors ShellAdapter.\_exec\_async) ===
$ sh -c 'echo first-command-output\\necho SECOND-STATEMENT-RAN-$((21\*2))'
first-command-output
SECOND-STATEMENT-RAN-42
\`\`\`

The three standard chaining attempts (\`;\`, \`&&\`, \`\|\`) are correctly rejected by the real filter, confirming it does real work; the newline-separated variant, expressing the same intent, is accepted by the identical filter in both restricted modes, and a real \`sh -c\` call confirms the shell executes both statements.

\#\#\# Impact
Any agent configured with \`SandboxShellTool(allowed=\[...\])\` or \`SandboxShellTool(readonly=True)\` — the two configurations the tool's own docstring presents as actual security boundaries, as opposed to \`blocked\`, which the same docstring explicitly says "is not a security boundary" — can be made to execute arbitrary shell commands via a single embedded newline in the command argument. Because tool arguments are LLM-generated and can be steered by content the agent processes (a fetched document, tool output, or any other text reaching the model — i.e. indirect prompt injection), this is reachable without the operator of the agent writing the malicious command themselves. With the default LocalEnvironment() backend, this is command execution on the host process running the agent, not confined to a container.

\#\#\# Suggested Remediation
- Add "\\n" and "\\r" to \`\_SHELL\_OPERATORS\` in \`ag2/tools/sandbox/filter.py\` so \`contains\_shell\_operator()\` rejects embedded newlines the same way it rejects \`;\`.
- - More robustly, execute allowlisted/readonly commands without invoking a shell in restricted mode (\`shlex.split\` + exec with no \`sh -c\` wrapper), so redirection, chaining, substitution, and every kind of statement separator are inert by construction instead of relying on an enumerated denylist.
\#\#\# Environment Tested
- Repository: github.com/ag2ai/ag2, commit a05ff1cb6ff4955ef252a4e0d4a27d3a32ad57f0 (main), cloned 2026-09-21.
- - PyPI package \`ag2\`, version 1.0.5 per pyproject.toml on this commit.
- - Python 3, stdlib only (\`subprocess\`, \`importlib\`) against the real, unmodified \`ag2/tools/sandbox/filter.py\` — no AG2 runtime dependencies required to reproduce.
-

## Affected and fixed versions

- PyPI `ag2`: affected \>= 0.13.2, \< 1.1.1; fixed 1.1.1 (ghsa)
- PyPI `autogen`: affected \>= 0.13.2, \<= 0.14.1; fixed no fix listed yet (ghsa)

## Technologies

PyPI packages

## Mitigation

- Upgrade ag2 to 1.1.1 or later.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2026-113663. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2026-113663.md
Affected: ag2 >= 0.13.2, < 1.1.1; autogen >= 0.13.2, <= 0.14.1
Fixed in: 1.1.1

Steps:
1. Search this machine and project for ag2 (PyPI), autogen (PyPI): dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2026-113663 being exploited?

There is no confirmed exploitation: CVE-2026-113663 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.63% chance of exploitation in the next 30 days (as of 2026-11-28).

### How serious is CVE-2026-113663?

High: CVSS 8.8 (v3.1, scored by GitHub). Remote, login needed.

### Which versions are affected by CVE-2026-113663?

ag2 \>= 0.13.2, \< 1.1.1; autogen \>= 0.13.2, \<= 0.14.1.

### Is there a fix for CVE-2026-113663?

Yes. Fixed in 1.1.1. Upgrade ag2 to 1.1.1 or later.

### How do I check if I'm affected by CVE-2026-113663?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- vendor: <https://github.com/ag2ai/ag2/security/advisories/GHSA-2h4w-29cv-2cmv>
- patch: <https://github.com/ag2ai/ag2/commit/3cd86726bb731eb11d6270f0ef9e50e42b5abb39>
- other: <https://nvd.nist.gov/vuln/detail/CVE-2026-113663>
- other: <https://github.com/ag2ai/ag2/releases/tag/v1.1.1>
- other: <https://github.com/advisories/GHSA-2h4w-29cv-2cmv>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- GitHub Advisory Database: CC-BY 4.0 <https://github.com/advisories/GHSA-2h4w-29cv-2cmv> (license: <https://creativecommons.org/licenses/by/4.0/>)
- FIRST EPSS: EPSS scores by FIRST <https://www.first.org/epss/>

HTML: <https://flawdb.com/CVE-2026-113663> · JSON: <https://flawdb.com/api/v1/entries/CVE-2026-113663>
