Friday, 4 December 2026
4 agent hacks today▼ 3 vs yesterday (7)

Newline character defeats AG2 shell tool command allowlist

A single line break lets an AG2 agent run arbitrary shell commands on the host, according to an advisory published on 10 November 2026.

By The Agentic Times ·

A guard dog sits before a locked gate as a handler slips a folded note through the bars—the dog reads only the first line, missing the hidden instructions underneath.
A guard dog sits before a locked gate as a handler slips a folded note through the bars—the dog reads only the first line, missing the hidden instructions underneath. · Illustration: The Agentic Times

A vulnerability in AG2's SandboxShellTool allows an AI agent to run arbitrary shell commands on the machine running it, bypassing both of the tool's documented security settings. The flaw, tracked as CVE-2026-113663, was published as a GitHub advisory on 10 November 2026 and affects the Python packages ag2 and autogen.

The tool offers two restricted modes. One accepts an explicit list of allowed commands. The other, readonly=True, uses a built-in list of read-only commands. According to the advisory, both can be defeated by putting a newline character inside the command string.

The reason is a mismatch between the filter and the execution path. The filter checks the command against a fixed list of shell metacharacters — the redirection, pipe and chaining symbols such as ;, &&, || and backticks. That list contains no entry for a newline or a carriage return. The command is then handed to sh -c as a raw string, and a POSIX shell treats an embedded newline exactly as it treats a semicolon: as a separator between two statements.

The advisory gives a worked example. A command beginning cat followed by a newline and then a destructive command passes the allowlist check, because the matching function only confirms the string starts with an approved prefix and never looks at the rest. It passes the operator check, because a newline is not on the list. It then runs both statements. The researcher reported the same bypass in readonly mode, using echo followed by a newline and id.

The finding was verified on 21 September 2026 against the AG2 main branch at commit a05ff1cb, corresponding to version 1.0.5 of the ag2 package. The advisory says the real, unmodified filter module was imported and the allowlist branch reproduced verbatim, using only the Python standard library. The three conventional chaining attempts using ;, && and | were correctly rejected, which the researcher says confirms the filter does real work; only the newline variant slipped through.

The practical severity depends on the backend. With the default LocalEnvironment() setting, the advisory notes, commands run as a subprocess on the host rather than inside a container. The tool's own docstring says that in this configuration "there is no real isolation". So the bypass is not an escape from a contained sandbox but direct command execution on the process running the agent.

The advisory stresses that the attacker does not need to be the operator. Tool arguments are generated by the language model, and the model can be steered by any text it processes — a fetched document, the output of another tool, or other content reaching the model. That makes the flaw reachable through indirect prompt injection, where malicious instructions are smuggled into data the agent reads.

The researcher recommends two fixes. The immediate one is to add newline and carriage return characters to the list of blocked shell operators, so they are rejected like a semicolon. The more durable one is to stop invoking a shell at all in restricted mode, splitting the command and executing it directly, which would make redirection, chaining and every form of statement separator inert by design rather than relying on an enumerated denylist.

The advisory also contrasts the two restricted modes with the tool's blocked option, which its documentation already says is not a security boundary. The allowlist and readonly settings were presented as boundaries that did hold.

Sources

  1. github.comhttps://github.com/advisories/GHSA-2h4w-29cv-2cmv