ag2 and autogen shell tool can run any command via newline in command string
What this means
An attacker can run any shell command on the host computer, even if the tool was set up to allow only specific commands or read-only operations. This includes reading, modifying, or deleting files, stealing credentials, or installing malware. The host computer is not sandboxed, so the attacker has the same access as the user running the Python code.
SecurityElites Manager Brief: the decision in one minute
A shell tool in ag2 and autogen agents can be tricked into running harmful commands that should have been blocked. An attacker who can influence what the agent does (through a prompt, chat message, or document) can take over the host computer. ag2 versions 0.13.2 to 1.1.0 need an update; autogen has no fix available yet.
| SecurityElites Fix-First Score | 43 of 100 Our own ranking of what to fix first. Real attacks count most, then the chance of attack, then severity. |
|---|---|
| SecurityElites fix window | Within 30 days High severity. This is our suggestion from common practice; your own policy comes first. |
| Who should own the fix | Platform or ML operations team (whoever manages Python dependencies for agents). |
| Likely effort | About 15 minutes for ag2: update the package and restart services. Autogen users cannot upgrade yet and must use a workaround. This estimate could grow if you run many services or if autogen is critical to your workflow. |
Questions to ask your team or supplier
- Do we use ag2 or autogen in production, and if so, which versions? For ag2: do we have a plan to upgrade to 1.1.1 or later this week?
- Do we use SandboxShellTool with allowed=[...] or readonly=True? If so, what is it allowed to do, and could an attacker control the commands through chat, documents, or API calls?
- If we use autogen and cannot upgrade, do we have a workaround in place to prevent newline injection, and have we tested it?
Message you can forward to the owning team
Security notice: ag2 and autogen shell tool can run any command via newline in command string (CVE-2026-113663)
Severity: High
SecurityElites Fix-First Score: 43 of 100
SecurityElites fix window: Within 30 days
Action: upgrade to ag2 1.1.1 or later.
What we need from you: confirm whether we run this software, who owns it, and the date it will be fixed.
Full guide: https://securityelites.com/ai-vulnerabilities/cve-2026-113663-ag2-and-autogen-shell-tool-can-run-any-command/
Source: SecurityElites AI Vulnerabilities Database, record SE-AIV-01134What is at stake in your AI setup
- Tools and systems the agent is connected to: an attacker can use the shell access to interact with databases, APIs, file stores, or other systems the agent normally talks to.
- Keys for AI providers and external services: if credentials are stored as environment variables or in files the agent can read, an attacker can steal them and abuse your API quota or impersonate your service.
- Training or retrieval data: an attacker can read, modify, or delete files used to fine-tune models or populate retrieval systems, poisoning your model or causing it to give wrong answers.
Who is exposed
- Teams running ag2 agents (versions 0.13.2 to 1.1.0) that accept user input, documents, or chat messages.
- Teams running autogen agents (all versions) with SandboxShellTool in allowed or readonly mode.
- Systems where the agent runs with broad file or network access.
- Not affected: systems using ag2 version 1.1.1 or later, or systems that do not use SandboxShellTool at all.
Upgrades you need
Am I affected?
Enter the version you run. Nothing you type is stored.
SecurityElites Developer Brief: the technical picture
| Is it being attacked | No known attacks and no public attack code when CISA last reviewed it |
|---|---|
| Where the attacker must be | Anywhere that can reach it over a network, including the internet if it is exposed |
| Account needed | An ordinary user account |
| Does a person have to do something | No. It works without anyone clicking or opening anything |
| How hard it is to do | Easy. It works reliably once the attacker can reach it |
| Risk of: data being read | High |
| Risk of: data or settings being changed | High |
| Risk of: the service being taken down | High |
| Can attackers automate it at scale | No, according to CISA. Each target needs manual work |
| How much control an attacker gains | Total control of the affected software, according to CISA |
Read from the official severity rating: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
Kind of coding mistake
- CWE-184
- CWE-78: operating system commands can be injected
Where it sits in the standards
OWASP Top 10 for LLM Applications 2025: LLM01 Prompt Injection
If you cannot upgrade today
- Until autogen is patched: do not use SandboxShellTool with `allowed=[...]` or `readonly=True` in production if the agent can receive input from users, documents, or other untrusted sources. Use alternative tools that do not interpret shell
- If you must use the shell tool, run agents in a container or virtual machine with no access to sensitive files or network, so a shell escape does not compromise your whole system.
- Inspect and log all commands before execution: wrap SandboxShellTool to filter out newlines, carriage returns, and other shell metacharacters (not just `;`, `|`, `&&`, `||`, backticks, and `$()`), then reject any command that contains them.
Signs it may already have been used against you
- Agent execution logs: look for commands that contain \n (backslash-n or actual newline) sent to SandboxShellTool.
- Shell or subprocess logs: look for unexpected commands or operations (file deletions, network calls, new processes) that do not match the allowed commands you configured.
- Agent output or chat history: look for messages that mention 'shell', 'command', or 'execute', especially if they come from external sources or seem unrelated to what the user asked for.
- File system: check for new, modified, or deleted files in directories the agent can access, especially outside your expected working directories.
SecurityElites Fix Guide: step by step
- Find where ag2 and autogen are installedList all Python environments and virtual environments your team uses to run agents. Check requirements.txt, pyproject.toml, Pipfile, or poetry.lock for ag2 and autogen. Run `pip list | grep -E 'ag2|autogen'` in each environment.
- Check which version of ag2 you haveIn each environment, run `pip show ag2` and note the version. If the version is 0.13.2 or later but earlier than 1.1.1, it is affected. If it says 'not installed', ag2 is not in use in that environment.
- Check which version of autogen you haveIn each environment, run `pip show autogen` and note the version. All autogen versions are affected until the maintainers release a fix. Write down the version number.
- Check if SandboxShellTool is in useSearch your agent code for 'SandboxShellTool' or 'sandbox' and 'shell'. Look for imports, instantiation, and configuration with `allowed=[...]` or `readonly=True`. Note the file paths and how the tool is configured.
- Upgrade ag2 to version 1.1.1 or laterIn each environment where ag2 is installed and affected, run `pip install --upgrade ag2>=1.1.1`. Restart all services and agents that use ag2.
- For autogen, apply a workaround until a fix is availableSee the workaround section below. The maintainers have not yet released a fixed version of autogen.
- Review logs and audit data from before the upgradeCheck whether anyone or any system tried to use newlines in commands sent to the shell tool. Look at conversation logs, API calls, and agent outputs from the last 30 days (or as far back as you can). If you find suspicious activity, isolate affected systems and check for unauthorized file changes or access.
- Test that the shell tool now blocks newline commandsWrite a test script that tries to send a command like 'ls\nid' to SandboxShellTool with allowed=['ls']. The command should be rejected with an error message, not executed. If the command runs, the fix did not work.
How to confirm it is fixed: Run a test command like 'ls\nid' with SandboxShellTool and allowed=['ls']. The tool should reject it with an error message mentioning shell operators are not permitted, not execute either command.
SecurityElites Quick Fixes: copy and paste
Upgrade ag2 with pipupgrade
pip install --upgrade "ag2>=1.1.1"
pip show ag2 | grep VersionPin it in requirements.txtupgrade
ag2>=1.1.1Check ag2 version in Pythonfor this issue
import ag2
print(ag2.__version__)Check autogen version in Pythonfor this issue
import autogen
print(autogen.__version__)List ag2 and autogen in current environmentfor this issue
pip list | grep -E 'ag2|autogen'Test in a non-production environment first. General hardening examples use placeholder names and ports; change them to match your setup.
Let your AI coding assistant do the upgrade
Paste this into the coding assistant you already use, inside the project. It checks first and asks before it changes anything.
Instruction for your coding assistant
You are helping me fix a security vulnerability (CVE-2026-113663) in this project.\n\n1. Search the whole repository, including lock files, container files and CI configuration, for these packages and list every place they are pinned or installed:\n - ag2 (PyPI): must be 1.1.1 or later
2. Tell me which version we use now and whether it is affected. Stop and ask me before changing anything.
3. After I agree, raise each one to the safe version, update the lock files, and keep every other dependency as it is.
4. Run the tests and tell me what failed.
5. Give me a short summary of the files you changed that I can put in the pull request.SecurityElites Incident Drill: could your team handle this?
Four questions to ask in your next team meeting. If any has no clear answer, that is the gap to close.
Ticket for your backlog
Paste into Jira, GitHub Issues or any tracker that reads Markdown.
Ready-made ticket
## ag2 and autogen shell tool can run any command via newline in command string (CVE-2026-113663)
**Severity:** High | **SE Fix-First Score:** 43/100 | **Fix window:** Within 30 days
**Record:** SE-AIV-01134 https://securityelites.com/ai-vulnerabilities/cve-2026-113663-ag2-and-autogen-shell-tool-can-run-any-command/
### Why this matters
An attacker can run any shell command on the host computer, even if the tool was set up to allow only specific commands or read-only operations. This includes reading, modifying, or deleting files, stealing credentials, or installing malware. The host computer is not sandboxed, so the attacker has the same access as the user running the Python code.
### What to do
1. Find where ag2 and autogen are installed: List all Python environments and virtual environments your team uses to run agents. Check requirements.txt, pyproject.toml, Pipfile, or poetry.lock for ag2 and autogen. Run `pip list | grep -E 'ag2|autogen'` in each environment.
2. Check which version of ag2 you have: In each environment, run `pip show ag2` and note the version. If the version is 0.13.2 or later but earlier than 1.1.1, it is affected. If it says 'not installed', ag2 is not in use in that environment.
3. Check which version of autogen you have: In each environment, run `pip show autogen` and note the version. All autogen versions are affected until the maintainers release a fix. Write down the version number.
4. Check if SandboxShellTool is in use: Search your agent code for 'SandboxShellTool' or 'sandbox' and 'shell'. Look for imports, instantiation, and configuration with `allowed=[...]` or `readonly=True`. Note the file paths and how the tool is configured.
5. Upgrade ag2 to version 1.1.1 or later: In each environment where ag2 is installed and affected, run `pip install --upgrade ag2>=1.1.1`. Restart all services and agents that use ag2.
6. For autogen, apply a workaround until a fix is available: See the workaround section below. The maintainers have not yet released a fixed version of autogen.
7. Review logs and audit data from before the upgrade: Check whether anyone or any system tried to use newlines in commands sent to the shell tool. Look at conversation logs, API calls, and agent outputs from the last 30 days (or as far back as you can). If you find suspicious activity, isolate affected systems and check for unauthorized file changes or access.
8. Test that the shell tool now blocks newline commands: Write a test script that tries to send a command like 'ls\nid' to SandboxShellTool with allowed=['ls']. The command should be rejected with an error message, not executed. If the command runs, the fix did not work.
### Done when
- [ ] ag2 is at 1.1.1 or later everywhere it is installed
- [ ] Lock files, container images and CI configuration are updated
- [ ] Run a test command like 'ls\nid' with SandboxShellTool and allowed=['ls']. The tool should reject it with an error message mentioning shell operators are not permitted, not execute either command.
- [ ] Logs were checked for signs of earlier use
SecurityElites Fix Tracker
Record who owns this fix, the date it is due and when it is done, and see everything still open in one list. Free with a SecurityElites account.
Change history
- 10 Nov 2026: Made public
- 1 Dec 2026: Published
Official record
### 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,
Weakness type: CWE-184, CWE-78
Use this record in your own tools
Get this record as JSON
curl https://securityelites.com/wp-json/se-aivd/v1/vulns/CVE-2026-113663For scanners and pipelines: OSV format · CycloneDX format · API guide · Email alerts · Fix tracker
The plain-language sections were written with AI from the official record, and the upgrade versions come directly from the official data. Last updated 10 Nov 2026. Read the vendor advisory before changing a production system.