/

CVE-2026-27952

Severity:

HIGH RISK

(8.8)

Code Injection / Sandbox Escape in Agenta Custom Code

CVE-2026-27952

Analyzed

Vulnerability type

Category:

Code Injection / Sandbox Escape

CWE:

CWE-94

Impact:

Remote Code Execution within the Agenta API server process

Severity:

HIGH RISK

(8.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

Agenta's self-hosted API server exposed an unsafe Python sandbox configuration that allowed authenticated users to escape the RestrictedPython environment and execute arbitrary code.

By leveraging the incorrectly whitelisted numpy package, specifically numpy.ma.core.inspect, an attacker could access system modules and invoke powerful functions such as os.system, leading to full remote code execution on the API server.

Affected context

This vulnerability appears in Agenta's self-hosted API server, specifically in the server-side custom code evaluator feature that executes user-supplied evaluator code.

The issue is present when:

  • The Agenta-API uses RestrictedPython for sandboxing
  • numpy is whitelisted as a safe module inside the sandbox
  • Users are allowed to submit or edit evaluator code via authenticated API or UI workflows

The SDK used purely as a local Python library, without the self-hosted API server's evaluator, is not directly affected.

Exploit preconditions

  • Attack surface: Agenta self-hosted API server's custom code evaluator endpoint or feature.
  • Required access: Authenticated access sufficient to define or modify evaluator code (e.g., project/user with "can run custom code" capability).
  • Trigger point: Submission or execution of specially crafted evaluator code inside the RestrictedPython sandbox that imports and uses numpy.ma.core.inspect.
  • Why exploitation is possible: The sandbox incorrectly treats numpy as safe, but numpy.ma.core.inspect exposes Python's introspection subsystem, including sys.modules. From there, the attacker can reach non-sandboxed modules (e.g., os) and invoke arbitrary system-level functions, breaking out of the RestrictedPython constraints.

Why this happens

The underlying flaw is an improperly configured execution sandbox combined with overbroad trust in a complex third-party library.

RestrictedPython was intended to constrain user-supplied evaluator code, but the sandbox's allowlist included numpy as a "safe" dependency.

numpy is not designed as a security-hardened library; through numpy.ma.core.inspect, it exposes Python's introspection tools (such as access to sys.modules), which in turn provide references to powerful system interfaces (e.g., os, subprocess).

This maps to CWE-94: Improper Control of Generation of Code (Code Injection) in the context of sandbox escape: user-controlled code is executed in an environment that is believed to be restricted but actually enables access to unrestricted interpreter capabilities.

Potential impact

  • Arbitrary command execution on the Agenta API server host via functions such as os.system or equivalents.
  • Compromise of all data accessible to the API process, including model configurations, prompts, and evaluation datasets.
  • Lateral movement to other internal services reachable from the API server's network environment.
  • Installation of backdoors or persistence mechanisms on the server.
  • Potential manipulation of evaluation results and pipelines (e.g., poisoning metrics or test outcomes).

General mitigation guidance

Effective mitigation centers on treating user-supplied code as fully untrusted and avoiding overreliance on in-process sandboxes:

  • Prefer out-of-process execution for user code, using isolated containers, VMs, or micro-VMs with strict OS-level controls (seccomp, user namespaces, read-only filesystems).
  • Avoid whitelisting large, general-purpose libraries (such as numpy) as "safe" within language-level sandboxes; assume that any sufficiently complex library can expose escape hatches.
  • If sandboxing is retained, adopt a default-deny policy: only expose minimal, purpose-built APIs rather than full libraries, and regularly review the allowlist for introspection or reflection capabilities.
  • Run the code-execution component with least privilege: non-root accounts, minimal filesystem access, restricted network egress, and tightly scoped credentials.
  • Separate duties: isolate evaluation services from core control-plane components and sensitive data stores, so that a sandbox escape has limited blast radius.

How teams detect issues like this

Organizations can detect and monitor for similar issues using multiple layers:

  • Static analysis and configuration review:
  • Search for use of RestrictedPython (or similar sandbox frameworks) alongside broad module allowlists.
  • Flag code paths where user-supplied code is executed in the same interpreter process as privileged application logic.
  • Review allowlisted libraries to identify those that support introspection, dynamic imports, or execution helpers.
  • Code review practices:
  • Require security review of features that execute user-defined code or templates.
  • Check for reliance on "safe" libraries without deep analysis of their APIs.
  • Runtime monitoring:
  • Monitor evaluator execution environments for unexpected module imports (e.g., os, subprocess, inspect) originating from sandboxed code.
  • Use audit logs or tracing to detect evaluator-related actions that spawn new processes or make network connections.
  • Automated tooling:
  • Integrate SAST tools and custom rules into CI/CD to flag insecure sandbox configurations and in-process execution of untrusted code.
  • Periodically run targeted security tests (including fuzzing and sandbox-escape probes) against endpoints that accept user code.

Sources

SourceLink
github.comgithub.com/Agenta-AI/agenta/security/advisories/GHSA-pmgp-2m3v-34mq

Frequently asked

questions

It is highly exploitable in environments where users are allowed to submit or edit evaluator code. Any authenticated user with such access can typically craft payloads that leverage numpy.ma.core.inspect to escape the sandbox and run code on the server.

The attacker must have authenticated access to the Agenta self-hosted API with permissions to define or execute custom evaluator code. No direct OS-level access is required; exploitation occurs entirely via the application layer.

The most robust pattern is to avoid running untrusted user code in the same interpreter process as the main application. Instead, run user code in isolated execution environments (e.g., containers or VMs) with strict OS-level sandboxing and minimal privileges, exposing only a controlled API surface.

Treat any feature that executes user-defined logic as a high-risk component. Avoid large "safe" allowlists, minimize exposed libraries, and prefer coarse-grained OS isolation over fine-grained language sandboxes. Incorporate security reviews, automated checks, and periodic penetration tests specifically for code-execution features.

Find out what's already
exploitable in your codebase.