Docs Give your agent tools

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.

In the portal Settings › Tools › Code sandbox (open it) Admin connects, checks and removes it. Everyone else sees its state and its last check.

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 over https.

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.

  1. 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.
  2. To offer run_shell too, 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
  3. Start the server with a long random token. It listens on 127.0.0.1:8790 by default and serves MCP at /mcp:
    ENTROPIX_SANDBOX_TOKEN=<secret> entropix-sandbox -gvisor -shell-image entropix-shell:1
  4. Put a TLS proxy in front of it, and let only the portal's address reach it.
FlagWhat it setsDefault
-token or ENTROPIX_SANDBOX_TOKENThe bearer token every request must carry. Required. The environment setting keeps it out of the process list.None
-addrWhere it listens127.0.0.1:8790
-imageThe Python image. Build your own from python:3.12-slim to add packages.python:3.12-slim
-packagesThe extra packages your image has, for example numpy,pandas, so the agent knows it can import themNone
-pythonThe Python version it reports. Asked of the image at start when empty.Empty
-gvisorRuns containers under gVisorOff
-shell-imageOffers run_shell, in containers of this imageOff
-max-timeoutThe longest a script may run, in seconds60
-max-memoryThe most memory a script may have, in MiB2048
-parallelScripts run at once4

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

  1. Open Settings › Tools › Code sandbox.
  2. Fill in Endpoint URL, for example https://sandbox.example.com/mcp.
  3. For the reference server, set Header name to Authorization and Header value to Bearer <token>. The value is stored encrypted and never shown again.
  4. Set Memory ceiling (MiB), from 256 to 2048 (default 512). No script gets more.
  5. Set Timeout ceiling (seconds), from 5 to 60 (default 30). A script is stopped at this time at most.
  6. 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 passesWhat it tests
network: blockedA script cannot reach the network.
timeout: enforcedA script that runs too long is stopped.
fresh: wrote the marker file and fresh: each call starts cleanA file written in one call is gone in the next.
sum: runs PythonA script runs and returns the right answer.
shell: runs bashOnly 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:

ObligationWho 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_code runs a Python 3 script. run_shell runs a bash script as bash -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, .txt or .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_call or gcp_call is kept as a file the agent can hand to run_code. Without a sandbox no file is kept, and the agent uses select to 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

You can
  • 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_code or run_shell ask first for one agent.
You can't
  • 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_code and run_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 (/mcp on 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_code stays 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.