Skip to content
RCE Write-up Advanced

Code Injection via Python Sandbox Escape — how I got a shell inside a network.

A web application's Python workbench allowed users to run scripts, but the sandbox could be escaped to execute arbitrary code. An attacker with an account could gain a shell inside the network.

Viktor Mares Follow

Published on medium.com

{{media:0}}

Viktor Mares, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

The target is a web application the author calls example.com, a placeholder used because of a non-disclosure agreement. The feature under test is a login-protected workbench that runs Python scripts to help users with daily tasks. The author registers and logs in, then turns to that workbench.

Viktor Mares
Viktor Mares From the original on medium.com

The report stops at the point where the workbench is introduced. It does not describe the requests sent, the payload used, the sandbox that was escaped, the shell obtained, the bounty, the severity or the fix. What follows is therefore limited to the setup the author gives: an authenticated Python execution feature, and a vulnerability class named in the title, code injection reached through a Python sandbox escape.

Root cause

The report does not analyse the cause. The title points to a Python sandbox escape, which likely means the workbench tried to restrict what submitted scripts could do and the restriction could be bypassed, letting the script run code outside the intended limits. The report gives no detail on how that restriction was built or where it failed.

Impact

The title states the outcome as a shell inside a network. The report gives no detail on what the shell could reach. The report does not describe the extent of that access, which systems were reachable, or what data was exposed.

How this kind of bug works

A sandbox for user-supplied code is an attempt to run untrusted scripts while denying them capabilities: file system access, process creation, network access, imports of dangerous modules. Python makes this hard because the language exposes many routes to the same capability. Builtins can be reached through object introspection, imported modules can expose the interpreter or the operating system, and anything that evaluates strings as code widens the surface further. A single missed route turns the sandbox into ordinary code execution.

The same pattern appears whenever an application accepts code or expressions from users: template engines, formula fields, query builders, rule engines and scripting workbenches. The mistake is usually treating a denylist of names or a restricted namespace as a security boundary, when the underlying runtime still offers ways to reach the objects that were meant to be removed.

How to test for it

  1. Find features that execute user-supplied code or expressions: scripting workbenches, custom formula or rule fields, template editors, report generators, automation hooks. Authenticate first; these features are often behind a login.
  2. Establish what the feature is supposed to allow. Run a trivial script and observe the output channel, so you can tell a successful escape from a script that simply failed.
  3. Probe for the boundary. Try to read a file, start a process, resolve a hostname or open a socket from inside the submitted script. Start with the least invasive check that would prove the sandbox is absent or broken.
  4. If direct calls are blocked, look for indirect routes: introspection over objects available in the script's namespace, imports that were not removed, helpers that evaluate strings, or libraries that wrap the interpreter or the shell.
  5. Confirm with a benign, reproducible action and record the exact request and response. A positive result is output that could only come from outside the sandbox, such as the contents of a file the script should not read or the result of a command the script should not run.
  6. Common false positives: the feature may be documented as running trusted code for trusted users, so check the intended trust model before reporting. Errors that look like blocks may come from a missing module rather than a security control. Output that appears to prove execution may be echoed input. Timeouts and crashes are not proof of escape on their own.

How it is fixed

The reliable fix is to stop running untrusted code in the same process as the application. Put script execution in a separate, low-privilege process or container with no credentials, a read-only file system, no network access and strict resource limits, and treat anything it returns as untrusted data. Where the feature only needs a narrow set of operations, replace free-form Python with a small declarative language or a fixed set of approved actions. Keep the runtime patched, since interpreter-level escapes are regularly found, and log script submissions so abuse is visible.

Hunting notes

These features hide in places that feel internal: admin panels, automation and workflow builders, data import and transformation tools, and anything described as a workbench, playground or sandbox. Recon signals include JavaScript bundles that reference a code editor or an interpreter, API routes that accept script bodies, and documentation that mentions Python, expressions or custom logic. Because the feature usually requires authentication, create an account and map what a normal user can reach before probing.

To make a report land, show the smallest reproducible step that crosses the boundary, keep the proof benign, and describe the reachable impact in concrete terms: what the process could read, which hosts it could contact, what credentials were available to it. If the program treats the feature as trusted-only, say so and explain why the trust assumption does not hold for the role you tested with.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 6 min read.

What happened, in plain words

A security researcher was testing a website, which they call example.com to keep the real name private under a non-disclosure agreement. A non-disclosure agreement, or NDA, is a promise not to reveal details about a company's systems. The site had a login screen. After creating an account and signing in, the researcher found a feature called a workbench: a page where users can write and run small Python programs to help with everyday tasks. Python is a popular programming language, and a program written in it is called a script.

Viktor Mares
Viktor Mares From the original on medium.com

The title of the write-up says the researcher escaped a Python sandbox and got a shell inside a network. A sandbox is an attempt to let code run while blocking it from doing anything harmful, a bit like letting a child play in a fenced garden: they can move around, but they cannot reach the road. A shell is a way to type commands directly into a computer and have it carry them out. So the claim is that a script submitted through the workbench broke out of its fenced garden and ended up running commands on a machine inside a network.

The write-up itself stops early. It introduces the login and the workbench and then does not describe the requests that were sent, the payload that was used, how the sandbox was built or where it failed, what the shell could reach, whether a reward was paid, how serious the issue was rated, or how it was fixed. What we can take from it is the shape of the problem: a feature that runs code on behalf of a logged-in user, and a boundary around that code that did not hold.

The setup, step by step

  1. The researcher registers an account on example.com and logs in. This matters because the workbench sits behind the login, so the feature is only reachable by someone with an account. That tells you the feature is only reachable by someone with an account.
  2. Inside the workbench, the user can submit Python scripts that the site runs for them. This is the interesting part: the site is taking text written by a user and executing it as a program. Any feature that does this is a candidate for code injection, which simply means getting your own code to run where the application expected only its own code to run.
  3. The title says the script escaped a sandbox and produced a shell inside a network. The report gives no further detail on this stage.

Why this kind of bug matters

When a website runs code you supply, the question is always: what is stopping that code from doing more than intended? If the answer is nothing, your script runs with the same powers as the website itself. In general, such code could read files on the server, start other programs, or open connections to other machines. That is why the outcome here is described as a shell inside a network: once you can run commands, the server becomes a starting point for looking around at whatever else it can talk to.

In general, how this kind of bug works

A sandbox for user code tries to allow some operations and deny others: reading files, starting processes, opening network connections, importing powerful parts of the language. Python makes this difficult because there are many different routes to the same capability. Objects you can reach in a script can lead, through introspection, to other objects that were meant to be out of reach. Modules that were not removed can expose the operating system. Anything that turns a string into code widens the surface further. One missed route and the sandbox is no longer a boundary.

The same pattern shows up in template engines, formula fields, query builders, rule engines and scripting workbenches. The usual mistake is treating a list of forbidden names, or a restricted namespace, as a security wall, when the underlying runtime still offers ways around it.

In general, how to test for it

  1. Look for features that run code or expressions you supply: scripting workbenches, custom formula or rule fields, template editors, report generators, automation hooks. Sign in first, because these features are often behind a login.
  2. Work out what the feature is meant to allow. Run a trivial script and see where the output appears, so you can tell a real escape from a script that simply failed.
  3. Probe the boundary with the least invasive check that would prove the sandbox is missing or broken: try to read a file, start a process, resolve a hostname or open a connection.
  4. If direct calls are blocked, look for indirect routes: introspection over objects available to the script, imports that were not removed, helpers that evaluate strings, or libraries that wrap the interpreter or the shell.
  5. Confirm with a harmless, repeatable action and record the exact request and response. A positive result is output that could only have come from outside the sandbox, such as the contents of a file the script should not be able to read.
  6. Watch for false positives. The feature may be documented as running trusted code for trusted users, so check the intended trust model first. An error that looks like a block may just be a missing module. Output that seems to prove execution may be your own input echoed back. Timeouts and crashes are not proof on their own.

In general, how it is fixed

The reliable fix is to stop running untrusted code in the same process as the application. Put script execution in a separate, low-privilege process or container with no credentials, a read-only file system, no network access and strict resource limits, and treat whatever it returns as untrusted data. Where the feature only needs a narrow set of operations, replace free-form Python with a small declarative language or a fixed list of approved actions. Keep the runtime patched, since interpreter-level escapes are found regularly, and log script submissions so abuse is visible.

Glossary

  • Non-disclosure agreement (NDA): a promise not to reveal details about a company's systems, which is why the site is called example.com here.
  • Python: a popular programming language; a program written in it is a script.
  • Script: a short program, here one submitted through the workbench.
  • Workbench: a page in the application where users write and run scripts to help with daily tasks.
  • Sandbox: an attempt to let code run while blocking it from doing anything harmful.
  • Sandbox escape: getting code to do something the sandbox was meant to prevent.
  • Shell: a way to type commands directly into a computer and have it carry them out.
  • Network: the set of machines that can talk to each other, here the internal systems behind the site.
  • Code injection: getting your own code to run where the application expected only its own code to run.
  • Payload: the specific input an attacker sends to trigger a vulnerability.
  • Request: the message a browser sends to a server asking for a page or an action.
  • Response: the message the server sends back.
  • Authentication: proving who you are, here by registering and logging in.
  • Introspection: a program examining its own objects at runtime, which can lead to objects that were meant to be out of reach.
  • Namespace: the set of names a script can see and use.
  • Denylist: a list of forbidden names or actions, which is easy to get wrong as a security boundary.
  • Container: an isolated environment for running a process, separate from the main application.
  • False positive: a result that looks like a vulnerability but is not one.
  • Trust model: the assumption about who is allowed to do what, for example whether a feature is only for trusted users.

More by Viktor Mares

View all

4 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.