Advanced levelPremium

RCE in a Python sandbox — from the bot editor to the server shell

An AI platform's Python sandbox didn't block os.popen(). Two lines of Python to run system commands, read environment variables and fingerprint the runtime.

Gorka El BochiMay 9, 202612 min

Quick answer

An AI platform let its users write bot logic in Python executed in a "sandbox." The sandbox didn't block the os module. Two lines (os.popen("env").read(), os.popen("whoami; uname -a").read()) were enough to run system commands, read internal environment variables and fingerprint the underlying runtime. Severity: Critical.


1. Context — what is the Python Sandbox?

The platform lets users create bots with custom logic by writing Python code directly in the app. This code runs in an environment called the "sandbox" when the bot receives messages.

The promise of the sandbox is that the code runs in a controlled, isolated environment. The bug found proves that that isolation doesn't exist: from the bot's Python code you can directly run operating-system commands on the server.


2. The bug — unrestricted shell access

The sandbox doesn't block the os module or the functions that let you run system commands. Specifically, os.popen() opens a shell subprocess and returns its output directly in the bot's response.

PoC A — Environment variables

python
import os
print(os.popen("env").read())

This code runs the env command on the server and returns all the process's environment variables. The observed output includes internal variables of the execution system and internal runtime paths (/__runtime/*), which reveal that the sandbox runs on a publicly known serverless Python platform.

Keep reading the full chain

The remaining part includes the step-by-step PoC, exploitation code and the full chain that led to impact. Available to subscribers.

Practice this in a lab

Rce

Solve

Keep learning · free account

Save your progress, unlock advanced payloads and rank your flags.

Create account

Related articles

hunters training
711

hunters training

labs from real reports
55

labs from real reports

completions
1,205

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy