Code sandbox
Connect a sandbox so agents can run Python and shell commands safely.
A code sandbox is a server you run or rent that executes the short scripts an agent writes, with no network. With one connected, agents can use run_code to run Python and run_shell to run bash: to parse a log, total a CSV, convert data or draw a plot. Your organisation has one sandbox, shared by every agent.
Before you start
- You need a server that speaks the sandbox contract,
entropix-sandbox/1. You can run the reference server described below, or use another that meets the same contract. - Run it on its own host or VM. Never run it on a host that holds databases, secrets or cloud credentials. The scripts are written by a model, so treat them as untrusted.
- Put it behind
https. A header secret is only ever sent overhttps.
Run the reference server
The reference server, entropix-sandbox, ships with Entropix. It runs each script in a new Docker container with no network and removes the container afterwards. The host needs Docker. gVisor (runsc) as a Docker runtime is strongly recommended.
- Pull the Python image first:
docker pull python:3.12-slim. The server never pulls an image itself, so a missing image fails at once. - To offer
run_shelltoo, build the shell image (bash, coreutils, grep, sed, awk, jq, yq, tar, gzip, openssl):docker build -t entropix-shell:1 -f cmd/entropix-sandbox/Dockerfile.shell cmd/entropix-sandbox - Start the server with a long random token. It listens on
127.0.0.1:8790by default and serves MCP at/mcp:ENTROPIX_SANDBOX_TOKEN=<secret> entropix-sandbox -gvisor -shell-image entropix-shell:1 - Put a TLS proxy in front of it, and let only the portal's address reach it.
| Flag | What it sets | Default |
|---|---|---|
-token or ENTROPIX_SANDBOX_TOKEN | The bearer token every request must carry. Required. The environment setting keeps it out of the process list. | None |
-addr | Where it listens | 127.0.0.1:8790 |
-image | The Python image. Build your own from python:3.12-slim to add packages. | python:3.12-slim |
-packages | The extra packages your image has, for example numpy,pandas, so the agent knows it can import them | None |
-python | The Python version it reports. Asked of the image at start when empty. | Empty |
-gvisor | Runs containers under gVisor | Off |
-shell-image | Offers run_shell, in containers of this image | Off |
-max-timeout | The longest a script may run, in seconds | 60 |
-max-memory | The most memory a script may have, in MiB | 2048 |
-parallel | Scripts run at once | 4 |
Each container runs with no network, a read-only file system, a 64 MiB /tmp, at most 64 processes and one CPU, as an unprivileged user with every capability dropped. The script arrives on standard input, never on the command line. The server logs one line per call and never the code.
Connect the sandbox
- Open Settings › Tools › Code sandbox.
- Fill in Endpoint URL, for example
https://sandbox.example.com/mcp. - For the reference server, set Header name to
Authorizationand Header value toBearer <token>. The value is stored encrypted and never shown again. - Set Memory ceiling (MiB), from 256 to 2048 (default 512). No script gets more.
- Set Timeout ceiling (seconds), from 5 to 60 (default 30). A script is stopped at this time at most.
- Choose Save and check.
The portal lists the server's tools, saves the sandbox and runs its check at once. The page head then shows Ready or Not ready: <why>, and how many agents have run_code on.
To change the header later, type a new value. Leave the value empty to keep the saved one, or tick Remove the saved header value. If you change the endpoint's host, you must type the header value again.
The check
The check makes real calls to the sandbox and tests what it promises. Last check shows Check passed or Check failed, the date, the contract and the Python version, then one line per test:
| Line when it passes | What it tests |
|---|---|
network: blocked | A script cannot reach the network. |
timeout: enforced | A script that runs too long is stopped. |
fresh: wrote the marker file and fresh: each call starts clean | A file written in one call is gone in the next. |
sum: runs Python | A script runs and returns the right answer. |
shell: runs bash | Only when the server offers a shell: a bash script runs. |
The check runs when you save, when you choose Check again, and by itself every 24 hours. run_code is offered only while the last check passed and is less than 48 hours old. run_shell is offered only when the last check also found a working shell. A failed shell test does not fail the check: run_code keeps working.
What the sandbox must do
The page lists the contract's seven obligations and which ones the portal checks:
| Obligation | Who makes sure |
|---|---|
| Run each call in a fresh, isolated environment destroyed after the call. | Checked by the portal |
| Give the script no network: no DNS, no TCP or UDP egress, no metadata service. | Checked by the portal |
| Kill the script at its timeout and say it timed out. | Checked by the portal |
| Cap memory, CPU, processes and disk. | Reported only |
| Run as a non-root user with no host mounts and no secrets in the environment. | Your vendor's job |
Return stdout and stderr cut to 64 KiB each, and only files under output/. | Checked by the portal |
| Not log or keep the code or data beyond the call. | Your vendor's job |
How run_code and run_shell work
Both are built-in tools, on for every agent and running freely by default. They are offered in plain chats and goals. An admin can turn either off, or make it ask first, on the agent's Connections tab. An Asks first call waits for a person: see Approve actions.
run_coderuns a Python 3 script.run_shellruns a bash script asbash -euo pipefail.- A script is at most 12 KiB. The agent can pass up to 5 text files of up to 256 KiB each; they appear in
input/. - A script times out after 30 seconds unless the agent asks for longer: up to 60 seconds, your timeout ceiling, or the sandbox's own limit, whichever is lowest.
- Files the script writes to
output/are attached to the answer:.csv,.md,.json,.txtor.png(up to 4096 × 4096). At most 3 files of 1 MiB each come back from one call. Attached files are kept 90 days. - One answer, or one step of a goal, makes at most 6 sandbox calls, counting both tools.
- Every call starts clean. Nothing carries over from one call to the next.
- A big answer from
aws_callorgcp_callis kept as a file the agent can hand torun_code. Without a sandbox no file is kept, and the agent usesselectto read only the parts it needs (see AWS and Google Cloud).
Remove the sandbox
Under Remove the code sandbox, choose Remove sandbox. Every agent's run_code and run_shell stop being offered. Their settings stay, so a new sandbox brings the tools back.
What you can and can't do
- Use the reference server, or any server that meets the contract.
- Cap memory and time for every script.
- Add Python packages by building your own image.
- Make
run_codeorrun_shellask first for one agent.
- Give scripts network access. A sandbox that allows it fails its check.
- Keep files between calls.
- Have more than one sandbox in an organisation.
- Give the sandbox to an agent as a tool server. It is reached only through
run_codeandrun_shell.
Troubleshooting
- "the server must list sandbox_info and run_python (contract entropix-sandbox/1)"
- The address answers, but not as a sandbox. Check the path (
/mcpon the reference server). - "the sandbox could not be listed: …"
- The portal could not reach it. Check the address, the TLS proxy and the token.
- "the endpoint's host changed: type the header value again"
- Re-enter the header value with the new address.
- "Not ready: the sandbox's last check is over 48 hours old"
- The daily check could not run or did not pass. Choose Check again.
- "network: the script reached the network …"
- The sandbox lets scripts out. Fix its network setting;
run_codestays off until the check passes. - "timeout: the script was not stopped at 2 s"
- The sandbox does not stop long scripts. Fix its timeout handling.