2026-11-26 15:51 UTC

Researcher reports AWS MCP Python sandbox escape; fix status needs confirmation

state: expiredheat: mediumuncertainty: mediumrelevance: mediumaws mcp-security sandbox-escapexplo1tAWS

What is this?

A security researcher, xplo1t, reports escaping the Python sandbox in AWS MCP Server’s `aws___run_script` tool, which runs user-supplied Python in a Lambda environment. The reported bypass used Python structural pattern matching to read restricted attributes and chain to system command execution. In the researcher’s test, it also exposed the Lambda role’s credentials, but those credentials were denied AWS API access except for `sts:GetCallerIdentity`; the researcher says they found no access to customer data or other sessions. The researcher reports disclosing the issue through AWS’s vulnerability disclosure program: AWS acknowledged a fix was in progress on September 15, 2026, and the report was marked resolved October 23, before public disclosure October 24. The supplied evidence does not independently establish the fix’s details or deployment status.

Why it matters

This is a meaningful security finding in an AI-agent tool that can run user-supplied Python while accessing AWS services. It illustrates how subtle Python language behavior can defeat sandbox controls, and why the permissions and isolation around agent tools matter as much as the model. The researcher says the escape was confined to their Lambda session and the exposed role credentials could not access customer data or AWS APIs beyond an identity check, which limits the reported impact.

Current assessment

Security researcher xplo1t reports that Python structural pattern matching bypassed attribute-access restrictions in AWS MCP Server’s `aws___run_script` sandbox, enabling system command execution and filesystem reads inside the Lambda environment. The reported chain also exposed the Lambda execution role’s credentials. In the researcher’s test, AWS-owned role credentials were denied API calls except `sts:GetCallerIdentity`; they report finding no access to customer data or other sessions. The researcher says AWS acknowledged the report on September 15, 2026, confirmed a fix was in progress, and marked it resolved October 23; public disclosure followed October 24. This is a researcher’s account, not independent confirmation of the exploit or remediation. Search results include a secondary claim that AWS fixed the issue and no customer action is required, but no linked primary AWS advisory or fix details are supplied here, so deployment status and any affected configurations remain uncertain. The finding is relevant to the security of agent-connected execution tools, but the supplied evidence does not establish customer compromise or broader exposure.

Measured heat

no measured readings yet — the hourly heat pass fills this in

How the heat travelled

10-23 13:00⭐ origin echo-reconstructedThe author says Python structural pattern matching bypassed sandbox restrictions on attribute access and formed an escape chain to system co
xplo1t on blog (echo) · attributed from hn.story.50254305
—
10-27 03:09first on hacker news · published · +86.2hBreaking the AWS MCP Python Sandbox
giuliomagnifico
—
10-27 03:09amplified on hacker news 👑hn.story.50254305
giuliomagnifico
peak 3 · 1 comments · 101% of case engagement
10-27 03:26our radar first saw it · +86.5hdiscovery anchor: hn.story.50254305—

Evidence (2) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnBreaking the AWS MCP Python Sandbox
Retrieved article excerpt

Open article · Retrieved 2026-10-27T03:28:16.522269+00:00

# Breaking the AWS MCP Python Sandbox

October 24, 2026 · 11 min

Table of Contents

- [Preface](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#preface)
- [Discovery](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#discovery)
- [Understanding the Sandbox](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#understanding-the-sandbox)
- [The Flaw: Attribute Reads Hidden in a Pattern](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#the-flaw-attribute-reads-hidden-in-a-pattern)
- [Building the Escape Chain](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#building-the-escape-chain)
  - [Recovering a Real Function](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#recovering-a-real-function)
  - [The Proxy That Completed the Chain](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#the-proxy-that-completed-the-chain)
- [Confirming Command Execution](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#confirming-command-execution)
- [The Impact](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#the-impact)
- [Closing Thoughts](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#closing-thoughts)
- [Vulnerability Disclosure Timeline](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#vulnerability-disclosure-timeline)

mcp-to-aws-sandbox-flow

## Preface[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#preface)

AWS announced the general availability of the [AWS MCP Server](https://aws.amazon.com/blogs/aws/the-aws-mcp-server-is-now-generally-available/) on May 6, 2026. It is a managed remote Model Context Protocol (MCP) server.

An MCP server exposes certain tools/functions and lets your AI agent call them. It extends your AI agent’s capabilities. The AWS MCP Server makes this possible for coding assistants such as Claude Code, Kiro and Cursor to retrieve current AWS documentation, make AWS API calls using the IAM credentials supplied by the user, and provide guidance through skills. Those tools can be used for tasks such as retrieving account information or creating an EC2 instance.

AWS’s MCP server provides a tool called `aws___run_script`. This tool accepts a short Python script as an argument and runs it in a server-side sandbox. Its purpose is to let an agent combine multiple AWS API calls, filter the responses and process the result in one request programatically, instead of making several separate calls.

The idea of user-supplied Python code executing inside an AWS managed sandboxed environment is interesting!

`aws___run_script` runs the supplied code in an AWS Lambda sandbox. The sandbox restricts imports, builtins, attribute access and file operations.

In this blog, I explain how I bypassed those Python restrictions and reached system command execution inside the Lambda environment.

I performed this research collaboratively with Claude Opus 4.6.

## Discovery[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#discovery)

Normally connecting the MCP server to Cursor or any other agent adds friction for security testing because your payloads have to pass through the AI agent which then invokes the tools. While it is fine for a while, but later it becomes a pain when your payloads starts become overly chaotic. So I quickly created a Python CLI as an MCP client that could let me enumerate the server’s tools and invoke them. The client used [`mcp-proxy-for-aws`](https://github.com/aws/mcp-proxy-for-aws), which signed requests with my local AWS credentials. I created a test IAM user in my AWS account with limited permissions for this assessment.

This made it possible to send controlled inputs to each tool and examine the returned results. Although the Python code ran inside the Lambda, dangerous Python code was immediately blocked due to the custom sandbox implemented, to prevent code execution inside the Lambda runtime. I wanted to find out what actually prevented it from reaching the process, filesystem or environment beneath the Python sandbox.

## Understanding the Sandbox[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#understanding-the-sandbox)

The submitted code passed through two layers of protection.

Firstly, a static validator inspected the code’s Abstract Syntax Tree (AST). An AST is a structured representation of source code. ASTs are used widely in compilers, code interpreters, linters, etc. An AST is a data structure containing the structural logic of the code such as imports, calls, attribute reads and assignments. The validator in the sandbox used AST to parse the Python script passed into `aws___run_script` to reject certain malicious looking operations before the code gets executed.

Secondly, a runtime layer replaced builtins with restricted implementations or proxy objects. In this context, a proxy is a replacement object that acts like the original object but limits how it can be used. For example, instead of the real `type()`, the script gets `_safe_type()` which returns restricted proxy classes that block access to sensitive attributes. The sandbox also limited `open()` to control file access.

For example, reading sensitive attributes through `obj.__class__` was blocked. The `getattr()` builtin was also blocked, as was importing `operator` to call `operator.attrgetter()`.

`getattr()` is simply another way to read an attribute. In normal Python, two lines produce the same output:

```
from types import SimpleNamespace

person = SimpleNamespace(name="John Doe", age=900)

print(person.name)  # John Doe
print(getattr(person, "name")) # John Doe
```

They both read `name` from `person`. When the attribute name is determined at runtime, `getattr()` is useful, as the attribute name can be passed as a string.

The sandbox covered both of these common forms of attribute access. It did not account for structural pattern matching.

## The Flaw: Attribute Reads Hidden in a Pattern[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#the-flaw-attribute-reads-hidden-in-a-pattern)

Python 3.10 introduced structural pattern matching through `match/case`. It checks whether a value fits a pattern and can bind parts of that value to names.

A class pattern first checks an object’s type, then reads attributes from it. Here is an example:

```
from collections import namedtuple

Coordinate = namedtuple("Coordinate", ["x", "y"])
location = Coordinate(10, 20)

match location:
    case Coordinate(horizontal, vertical):
        print(horizontal, vertical)
```

This would print `10 20`.

Python decides which attributes go into `horizontal` and `vertical` by looking at `__match_args__` on the class.

```
print(Coordinate.__match_args__)  # ('x', 'y')
```

Names wrapped in double underscores are often called dunder names (dunder comes from double underscore). They are special names used by Python’s object model.

For the `Coordinate` class, `__match_args__` contains:

```
("x", "y")
```

So the first position in the pattern reads `x` and the second reads `y`. This tuple can be changed:

```
Coordinate.__match_args__ = ("y", "x")
```

With that change, the exact same pattern prints `20 10`. The tuple controls which attributes Python reads for the positional entries in the pattern.

[PEP 634](https://peps.python.org/pep-0634/#class-patterns) specifies this class-pattern behaviour. CPython performs these attribute lookups internally, so they happen even if the `getattr()` builtin exposed to user code has been removed.

That matters for an AST validator. The validator on the sandbox only looks at the structure of the submitted code, and it was built to reject nodes that read sensitive attributes, such as `obj.__class__` (an attribute access) or `getattr(obj, "__class__")` (a call to a blocked builtin).

A class pattern produces neither. In the AST, it is a single `ast.MatchClass` node containing the class name and the names to bind. The attribute name never appears in the code at the point where the read happens. It is stored in `__match_args__`, and Python only looks it up while evaluating the pattern at runtime.

Here is the same `Coordinate` example with `__match_args__` pointed at a different attribute:

```
Coordinate.__match_args__ = ("__class__",)

match location:
    case Coordinate(c):
        print(c)
```

This prints `<class '__main__.Coordinate'>`. The pattern `Coordinate(c)` has a single positional entry, so Python reads the first name in `__match_args__`, which is now `__class__`, from `location` and binds the result to `c`. The code above never directly specified `location.__class__`, but that value came up in `c`.

Two conditions had to hold in the sandbox for this to be useful:

- Assigning to `__match_args__` was permitted. The validator blocked reading dunder attributes but it checked writes only against a short denylist of dunder names, and `__match_args__` was not on it.
- Class patterns still performed their implicit reads, because the check lives inside CPython and not in the validator or the replaced builtins.

Together with those two, we can read attributes that the normal syntax could not reach. `__class__` is just an example here. This same trick works for any attribute name, including the ones the sandbox was intended to block.

There was one more hurdle. The validator also rejected dunder names written as plain strings. So `("__class__",)` was blocked. I got around this by building the string at runtime using `chr()`, where the validator could not see it:

```
"__class__"                        # blocked by the validator
chr(95)*2 + "class" + chr(95)*2    # allowed
```

`chr(95)` is the underscore `_` character. I used this for every dunder name in the chain such as `__reduce_ex__`, `__globals__` and `__import__`.

## Building the Escape Chain[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#building-the-escape-chain)

I began with `collections.namedtuple()`, which was available in the sandbox. Calling it creates a tuple subclass with named fields, like `Coordinate` in the earlier example. The resulting class’s `__match_args__` can be reassigned.

This was useful because the sandbox removed `__build_class__` from the exposed builtins, preventing ordinary class definitions. However, `namedtuple()` creates its class internally using `type(...)`, so this allowed standard-library function still gave me a way to obtain a class and control its `__match_args__`.

### Recovering a Real Function[#](https://xplo1t-sec.github.io/posts/breaking-the-aws-mcp-python-sandbox/#recovering-a-real-function)

There were probably many other candidates, but after testing several, I ended up with `__reduce_ex__`.

`__reduce_ex__` belongs to Python’s serialization support. When `pickle` needs to reconstruct an object later, it can ask the object for a recipe: a callable, arguments and any required state.

After changing the namedtuple class’s `__match_args__` to `("__reduce_ex__",)`, a class pattern retrieved the instance’s `__reduce_ex__` method. Calling it with protocol `4` returned a recipe whose first element was `copyreg.__newobj__`.

`copyreg.__newobj__` was a real Python function, rather than a proxy function in the sandbox.

This is important because a function defined in Python exposes `__globals__` which is a dictionary of global names in the module where it was defined. The globals for `copyreg.__newobj__` included `__builtins__`, the original Python builtins dictionary.

`__builtins__` contains `__import__`, which we can use to load different modules. If I could recover that original import function, I could import `os` and `subprocess`.

The next challenge was obtaining the real function’s `__globals__` with another class pattern. The namedtuple pattern couldn’t be reused here, because a class pa
giuliomagnifico31
🟧 echo.blog ⭐The author says Python structural pattern matching bypassed sandbox restrictions on attribute access and formed an escape chain to system coxplo1t——

Interpretation history

Decision trace