Skip to main content

Run Code Tutorial

Goal: Ask the agent to write and run Python in an isolated sandbox.

Prerequisites: Quickstart completed, platform running.

Time: ~5 minutes

1. Ask for a Calculation

In chat, ask:

Calculate the first 20 Fibonacci numbers and show them in a table.

The agent writes Python, sends it to the sandbox, and streams stdout and any generated artifacts back into the tool timeline.

2. Ask for a Chart

Create a bar chart comparing the populations of the 5 largest countries.

Matplotlib images are collected as sandbox artifacts and attached to the response.

3. Use the Gateway Sandbox API

Public sandbox calls go through the gateway under /v1/sandbox/*:

curl http://localhost:8080/v1/sandbox/execute \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"code": "import sys\nprint(sys.version)",
"language": "python",
"tenant_id": "default",
"session_id": "demo"
}'

Direct localhost:8006 calls are a dev-only service-port shortcut.

4. Admin Session Listing

Listing or deleting sandbox sessions is an admin operation:

curl "http://localhost:8080/v1/sandbox/sessions" \
-H "Authorization: Bearer $ADMIN_TOKEN"

5. Isolation Summary

  • Each tenant/session pair gets a separate workspace.
  • Docker backend containers run without network access by default.
  • E2B backend is available with SANDBOX_BACKEND=e2b and deploy/docker-compose.e2b.yml.
  • Idle sessions are cleaned up after SANDBOX_IDLE_TIMEOUT.

See Code Sandbox Reference.