-
Notifications
You must be signed in to change notification settings - Fork 1
Code Execution
Two tiers of sandboxed code execution, paywalled via x402. An agent sends source code and gets back stdout, stderr, and the expression result -- all executed in an isolated cloud VM via E2B. No API key needed on the caller's side, no signup, no account. The operator's own E2B_API_KEY handles upstream auth; per-tier timeout and code-size caps bound compute cost.
| Endpoint | Price | Timeout | Code cap | Languages |
|---|---|---|---|---|
POST /api/code-run |
$0.02 | 30s | 10,000 chars | Python, JavaScript |
POST /api/code-run-pro |
$0.05 | 60s | 50,000 chars | Python, JavaScript |
Both tiers are wallet-only -- there is no proof-of-work free tier because every call spins up a real cloud VM. See Security Model for the wallet-only rationale.
Both tiers accept the same JSON body:
{
"code": "print('Hello from Agent402!')",
"language": "python"
}| Field | Required | Notes |
|---|---|---|
code |
yes | Source code to execute; max length varies by tier |
language |
no |
python (default) or javascript
|
Both tiers return the same envelope:
{
"language": "python",
"stdout": "Hello from Agent402!\n",
"stderr": "",
"result": null,
"error": null
}| Field | Description |
|---|---|
language |
The language the code was executed in |
stdout |
Standard output from the execution |
stderr |
Standard error from the execution |
result |
The value of the last expression (if any) |
error |
Error details if the code failed, or null
|
When code raises an exception, the error field contains:
{
"error": {
"name": "NameError",
"message": "name 'x' is not defined",
"traceback": "Traceback (most recent call last):\n ..."
}
}curl -X POST https://agent402.tools/api/code-run \
-H 'Content-Type: application/json' \
-d '{
"code": "import math\nprint(f\"Pi is approximately {math.pi:.10f}\")\nmath.factorial(20)",
"language": "python"
}'curl -X POST https://agent402.tools/api/code-run \
-H 'Content-Type: application/json' \
-d '{
"code": "const fib = n => n <= 1 ? n : fib(n-1) + fib(n-2); console.log(fib(10)); 55",
"language": "javascript"
}'curl -X POST https://agent402.tools/api/code-run-pro \
-H 'Content-Type: application/json' \
-d '{
"code": "import numpy as np\narr = np.random.randn(1000000)\nprint(f\"mean={arr.mean():.4f}, std={arr.std():.4f}\")\narr.shape",
"language": "python"
}'All endpoints return 402 without a valid x402 payment header -- the same flow as every other paid tool. See Paying with x402 for how to sign and attach payment.
Each call runs in a fully isolated E2B sandbox (ephemeral cloud VM):
- No access to the Agent402 server's filesystem, network, or secrets
- No state persists between callers -- the VM is destroyed after each execution
- Timeout enforcement prevents infinite loops from burning compute
- Code size cap prevents payload abuse
- The
E2B_API_KEYis read at call time and never exposed in responses or error messages
The kit lazy-loads the E2B SDK and reads E2B_API_KEY at call time, not at boot. If the key is missing or empty, calls return 503 Service Unavailable and the rest of the server continues running normally. Self-hosters who don't want to offer code execution simply omit the env var -- no code change needed.
- LLM Proxy Gateway -- text inference proxy
- Image Generation Gateway -- image generation proxy
- Paying with x402 -- the USDC payment flow these endpoints require
- Security Model -- why these tools are wallet-only (no PoW free tier)
- Tool Catalog -- where these tools sit in the catalog
agent402.tools · synced from wiki/ in the main repo — edit there, not here.
Using it (for agents / buyers)
- Getting Started
- Paying with x402
- Paying with Compute
- MCP Connector
- Adapters
- AWS Bedrock AgentCore
- Tool Catalog
- Skill Packs
- x402 Index and Router
- x402 Leaderboard
- LLM Proxy Gateway
- Image Generation Gateway
- Code Execution Sandbox
- Text-to-Speech
- Speech-to-Text
- Text Embeddings
- Payments and x402
- Memory and Coordination
Tollbooth (for site owners)
- Pay-per-crawl — what it is, install, modes
- Pay-per-crawl Walkthrough — 5-min hands-on
- Tollbooth for Agencies — many-site playbook
- Try Tollbooth Cloud (managed)
Website & Developer
- Quickstart — first call in 60 seconds
- Playground — try tools in your browser
- SDK REPL — live code editor
- API Explorer — browse OpenAPI
- Adapter Docs — per-framework guides
- Workflows — chaining patterns
- Blog · Changelog
Under the hood