MS-Agent command injection through the Shell tool
An agent with shell access can turn attacker-controlled input into operating-system commands.
The execution boundary must validate the requested operation and restrict the process's permissions.
CVE-2026-2256 documents this failure in the MS-Agent Shell tool.
The vulnerability
A command injection vulnerability in ModelScope's MS-Agent framework allows attackers to execute arbitrary operating system commands through crafted prompt-derived input. Affected versions: 1.6.0rc1 and earlier.
MS-Agent is an open-source framework for building AI agents. It includes a Shell tool that lets agents execute operating system commands for tasks like file management and automation.
The problem: the Shell tool's safety checks don't actually work.
The root cause: an incomplete command blocklist
The Shell tool attempts to prevent dangerous commands using a check_safe() function. It uses a blocklist of patterns such as rm -rf, sudo, and curl | bash.
This shortened example illustrates the check:
dangerous_commands = [
r'\brm\s+-rf\s+/', # rm -rf /
r'\bsudo\b', # sudo
r'\bcurl\b.*\|\s*bash', # curl | bash
# ... more patterns
]
for pattern in dangerous_commands:
if re.search(pattern, command, re.IGNORECASE):
raise ValueError('Command contains dangerous operation')
The published reproducer bypasses the check by invoking Python, which the blocklist permits. Python can execute code with the same privileges as the agent process.
Other interpreters and shell syntax also need review when a tool permits arbitrary command strings. Checking a few dangerous names does not bound what the remaining commands can do.
How the attack works
An attacker doesn't need direct access to the agent. They inject crafted content into data sources the agent consumes:
- Malicious document. Agent is asked to analyze a PDF containing hidden prompt injection
- Poisoned log file. Agent reads logs that include attacker-controlled strings
- Research input. Agent fetches web content that includes shell metacharacters
The agent, doing exactly what it was designed to do, processes this input and passes it to the Shell tool. The regex check sees no blocklisted patterns. The shell sees executable code.
Key insight: The attacker never interacts with the shell directly. They interact with the agent's input pipeline, and the agent does the rest.
Impact
Remote code execution
Execute arbitrary OS commands as the agent's user
Secret exposure
Access API keys, tokens, configuration files, agent memory
System tampering
Modify files, implant persistence mechanisms
Lateral movement
Pivot to internal services using stolen credentials
The broader pattern
The same configuration pattern can expose other agent deployments:
- Agents get production access. shell execution, file system access, API credentials
- Safety relies on input filtering. blocklists, regex patterns, prompt-level guardrails
- Attackers control upstream data. documents, web content, logs, user messages
- The agent bridges the gap. turning filtered input into unfiltered execution
The blocklist leaves powerful interpreters available. Restrict the operation the tool may perform and the permissions of its process.
What actually works
Check the maintainer's current release and advisory before deployment. Remove shell access from agents whose tasks do not require it.
For high-risk operations like shell execution, effective controls require:
- Allowlisting over blocklisting. explicitly permit known-safe commands rather than blocking known-bad patterns
- Execution context isolation. sandboxed environments where shell access can't reach production resources
- Runtime monitoring. behavioral analysis that detects anomalous command patterns regardless of how they were constructed
- Principle of least privilege. agents shouldn't have shell access unless they demonstrably need it
The regex blocklist approach will always have gaps. Shells are Turing-complete interpreters with decades of edge cases. No pattern list can anticipate every encoding trick, every metacharacter combination, every creative bypass.
Deployment checks
CVE-2026-2256 is a textbook example of what happens when we give AI agents production capabilities without production-grade security controls.
A blocklist can miss shell syntax that still produces an unauthorized operation. Restrict available commands and isolate the execution environment.
Review wrappers around execution tools as well as the model's instructions.
This analysis is based on publicly disclosed vulnerability information and independent technical review.
Sources: CVE record and researcher's reproducer and explanation.