/

CVE-2026-51922

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-94) in AgentScope Shell Command

CVE-2026-51922

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A critical code injection vulnerability in AgentScope's execute_shell_command function may allow attacker-controlled code or operating-system commands to run.

The risk depends on whether an exposed application entry passes attacker-influenced data to this function without adequate authorization, validation, or isolation.

A critical code injection vulnerability in AgentScope's execute_shell_command function may allow attacker-controlled code or operating-system commands to run.

The risk depends on whether an exposed application entry passes attacker-influenced data to this function without adequate authorization, validation, or isolation.

Affected context

The vulnerability occurs in AgentScope v1.0.20 within the shell-command execution component at src/agentscope/tool/_coding/_shell.py. It becomes risky when an externally reachable agent, tool, workflow, or application entry can supply data that reaches execute_shell_command and the execution path does not enforce a trusted-command policy or strong isolation.

The vulnerability occurs in AgentScope v1.0.20 within the shell-command execution component at src/agentscope/tool/_coding/_shell.py. It becomes risky when an externally reachable agent, tool, workflow, or application entry can supply data that reaches execute_shell_command and the execution path does not enforce a trusted-command policy or strong isolation.

Exploit preconditions

  • Attack surface: An application or agent entry that exposes the shell-command execution capability
  • Required access: Ability to invoke the exposed entry or influence data processed by it
  • Trigger point: Processing attacker-controlled input by execute_shell_command
  • Why exploitation is possible: Untrusted data can reach a command or code execution boundary without sufficient restrictions on what may be executed
  • Attack surface: An application or agent entry that exposes the shell-command execution capability
  • Required access: Ability to invoke the exposed entry or influence data processed by it
  • Trigger point: Processing attacker-controlled input by execute_shell_command
  • Why exploitation is possible: Untrusted data can reach a command or code execution boundary without sufficient restrictions on what may be executed

Why this happens

The underlying issue is an unsafe trust boundary between externally influenced input and a function that executes shell commands. When command content or execution parameters are constructed from untrusted data without strict allowlisting, separation of arguments, and authorization checks, the data can be interpreted as executable instructions. This behavior maps to CWE-94: Improper Control of Generation of Code, because attacker-controlled input may influence code or command execution.

The underlying issue is an unsafe trust boundary between externally influenced input and a function that executes shell commands. When command content or execution parameters are constructed from untrusted data without strict allowlisting, separation of arguments, and authorization checks, the data can be interpreted as executable instructions. This behavior maps to CWE-94: Improper Control of Generation of Code, because attacker-controlled input may influence code or command execution.

Potential impact

  • An attacker may execute arbitrary commands with the privileges of the AgentScope process
  • The application environment could be compromised
  • Sensitive files, credentials, or environment data could be accessed
  • The vulnerability could enable data alteration, service disruption, or persistence
  • Compromised hosts could be used for lateral movement when network permissions allow it
  • An attacker may execute arbitrary commands with the privileges of the AgentScope process
  • The application environment could be compromised
  • Sensitive files, credentials, or environment data could be accessed
  • The vulnerability could enable data alteration, service disruption, or persistence
  • Compromised hosts could be used for lateral movement when network permissions allow it

General mitigation guidance

Mitigation generally focuses on removing unnecessary shell execution and reducing the amount of untrusted input that can reach execution boundaries.

Common defensive patterns include:

  • Prefer fixed, non-shell APIs with structured argument handling over dynamically assembled shell commands
  • Enforce explicit command and argument allowlists for any required execution capability
  • Separate untrusted values from executable command structure and validate them against strict schemas
  • Require authorization at the tool and workflow boundaries before execution
  • Run execution tasks in isolated, least-privileged environments with restricted filesystem and network access
  • Avoid exposing shell-capable tools to untrusted users or autonomous workflows unless the trust boundary is explicit
  • Apply resource limits, auditing, and process isolation as defense-in-depth controls

Mitigation generally focuses on removing unnecessary shell execution and reducing the amount of untrusted input that can reach execution boundaries.

Common defensive patterns include:

  • Prefer fixed, non-shell APIs with structured argument handling over dynamically assembled shell commands
  • Enforce explicit command and argument allowlists for any required execution capability
  • Separate untrusted values from executable command structure and validate them against strict schemas
  • Require authorization at the tool and workflow boundaries before execution
  • Run execution tasks in isolated, least-privileged environments with restricted filesystem and network access
  • Avoid exposing shell-capable tools to untrusted users or autonomous workflows unless the trust boundary is explicit
  • Apply resource limits, auditing, and process isolation as defense-in-depth controls

How teams detect issues like this

Detection can include static analysis and review rules for calls to execute_shell_command, subprocess APIs, shell invocation flags, dynamic command construction, and string interpolation near execution sinks. Code review should examine whether externally supplied agent messages, tool arguments, workflow data, or configuration values can reach these paths.

Runtime monitoring may flag unexpected child processes, commands outside an approved policy, unusual process ancestry, and shell activity from services that do not normally execute commands. CI and policy enforcement can require command allowlists, prohibit shell execution in untrusted request paths, and surface risky data flows through automated review tools.

Detection can include static analysis and review rules for calls to execute_shell_command, subprocess APIs, shell invocation flags, dynamic command construction, and string interpolation near execution sinks. Code review should examine whether externally supplied agent messages, tool arguments, workflow data, or configuration values can reach these paths.

Runtime monitoring may flag unexpected child processes, commands outside an approved policy, unusual process ancestry, and shell activity from services that do not normally execute commands. CI and policy enforcement can require command allowlists, prohibit shell execution in untrusted request paths, and surface risky data flows through automated review tools.

Sources

SourceLink
gist.github.comgist.github.com/Ro1ME/78910899a99e2ba702d588e477d0755f
github.comgithub.com/agentscope-ai/agentscope/issues/1645

Frequently asked

questions

It can be remotely exploitable when a network-accessible application, agent, or tool exposes the vulnerable execution path and permits attacker-controlled input to reach it. Exploitability depends on the surrounding integration and access controls.

The attacker generally needs permission to invoke an exposed entry or influence input processed by the AgentScope workflow. The required level may range from unauthenticated access to an authenticated role, depending on the deployment.

The safest pattern is to avoid shell execution for untrusted workflows and replace it with narrowly scoped, non-shell operations using fixed commands and structured arguments. If execution is necessary, use strict allowlists, authorization, and isolation.

Treat agent and tool inputs as untrusted, enforce execution policies at every boundary, review data flows into process-launch APIs, and run necessary commands with minimal privileges and limited filesystem and network access.

It can be remotely exploitable when a network-accessible application, agent, or tool exposes the vulnerable execution path and permits attacker-controlled input to reach it. Exploitability depends on the surrounding integration and access controls.

The attacker generally needs permission to invoke an exposed entry or influence input processed by the AgentScope workflow. The required level may range from unauthenticated access to an authenticated role, depending on the deployment.

The safest pattern is to avoid shell execution for untrusted workflows and replace it with narrowly scoped, non-shell operations using fixed commands and structured arguments. If execution is necessary, use strict allowlists, authorization, and isolation.

Treat agent and tool inputs as untrusted, enforce execution policies at every boundary, review data flows into process-launch APIs, and run necessary commands with minimal privileges and limited filesystem and network access.

Find out what's already
exploitable in your codebase.