sandbox_code_execute
Execute Python, JavaScript, TypeScript, or Bash code inside an ephemeral isolated E2B cloud microVM sandbox and return stdout, stderr, structured outputs, and execution errors.
When to use
Use when an agent needs to run untrusted or computational code, verify scripts, process data, or execute shell commands in an isolated cloud sandbox.
Selection guidance
Role: primary. Use when an agent needs to run untrusted or computational code, verify scripts, process data, or execute shell commands in an isolated cloud sandbox.
Use cases
- python code execution
- javascript code execution
- isolated bash sandbox
- data analysis script run
- verify generated code
Access
- REST:
POST https://api.rafidsystem.com/api/v1/sandbox/execute - x402:
POST https://api.rafidsystem.com/api/v1/x402/sandbox/execute - MCP tool:
sandbox_code_execute - Free preview:
POST https://api.rafidsystem.com/api/v1/preview/sandbox_code_execute
Price: $0.05 USD per call. Payment options are deployment-configured; inspect /api/v1/payment-methods. Prices and payment semantics are unchanged from the canonical registry.
Get the full result
0.05 USD per call
Try free preview · limited information, no charge
curl -X POST 'https://api.rafidsystem.com/api/v1/preview/sandbox_code_execute' -H 'Content-Type: application/json' --data '{"language":"python","code":"x = 21 * 2\nprint(f'\''Result: {x}'\'')\nx","timeoutMs":30000}'Pay with USDC · request an x402 challenge
curl -X POST 'https://api.rafidsystem.com/api/v1/x402/sandbox/execute' -H 'Content-Type: application/json' --data '{"language":"python","code":"x = 21 * 2\nprint(f'\''Result: {x}'\'')\nx","timeoutMs":30000}'Authorized x402 client · signed retry request
curl -X POST 'https://api.rafidsystem.com/api/v1/x402/sandbox/execute' -H 'Content-Type: application/json' -H 'PAYMENT-SIGNATURE: <PAYMENT_SIGNATURE_FROM_AUTHORIZED_CLIENT>' -H 'X-Rafid-Payment-Journey: <PAYMENT_JOURNEY_FROM_CHALLENGE>' -H 'Idempotency-Key: <UNIQUE_REQUEST_ID>' --data '{"language":"python","code":"x = 21 * 2\nprint(f'\''Result: {x}'\'')\nx","timeoutMs":30000}'Use an x402-compatible client to parse PAYMENT-REQUIRED and authorize payment before retrying the same input with PAYMENT-SIGNATURE. Copying a request does not pay.
No crypto wallet? Use Rafid Credits
curl -X POST 'https://api.rafidsystem.com/api/v1/sandbox/execute' -H 'Content-Type: application/json' -H 'Authorization: Bearer <RAFID_API_KEY>' -H 'X-Rafid-Payment-Method: credits' -H 'Idempotency-Key: <UNIQUE_REQUEST_ID>' -H 'X-Rafid-Payment-Journey: <PAYMENT_JOURNEY_FROM_CHALLENGE>' --data '{"language":"python","code":"x = 21 * 2\nprint(f'\''Result: {x}'\'')\nx","timeoutMs":30000}'Create an API key instantly via POST https://api.rafidsystem.com/api/v1/account/signup or at https://api.rafidsystem.com/get-started, then fund by card (Stripe) or USDC and save with monthly plans ($10–$500/mo).
Existing account balance: GET https://api.rafidsystem.com/api/v1/account/balance.
MCP Credits integration
POST https://api.rafidsystem.com/mcp/credits
Authorization: Bearer <OAUTH_ACCESS_TOKEN>
Idempotency-Key: <UNIQUE_REQUEST_ID>
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "sandbox_code_execute",
"arguments": {
"language": "python",
"code": "x = 21 * 2\nprint(f'Result: {x}')\nx",
"timeoutMs": 30000
}
}
}OAuth metadata: authorization server · protected resource. Operator authorization and an existing funded account are required; OAuth does not grant credits.
Payment instructions and onboarding · API docs and schemas
These are copyable API integration requests. They do not open a checkout or execute a paid tool.
Example input
{
"language": "python",
"code": "x = 21 * 2\nprint(f'Result: {x}')\nx",
"timeoutMs": 30000
}Example output
{
"language": "python",
"sandboxId": "sbx_example_0001",
"stdout": "Result: 42\n",
"stderr": "",
"text": "42",
"results": [
{
"isMainResult": true,
"text": "42"
}
],
"error": null,
"executionMs": 1240,
"provider": "e2b",
"tier": "hobby_sandbox"
}Input schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"code": {
"type": "string",
"minLength": 1,
"maxLength": 65536,
"description": "Source code or shell commands to execute inside an isolated E2B cloud microVM sandbox."
},
"language": {
"default": "python",
"description": "Runtime language for execution.",
"type": "string",
"enum": [
"python",
"javascript",
"typescript",
"bash"
]
},
"timeoutMs": {
"default": 30000,
"description": "Execution timeout in milliseconds (1000 to 60000).",
"type": "integer",
"minimum": 1000,
"maximum": 60000
},
"envs": {
"description": "Optional environment variables injected into the sandbox execution.",
"type": "object",
"propertyNames": {
"type": "string",
"minLength": 1,
"maxLength": 64
},
"additionalProperties": {
"type": "string",
"maxLength": 4096
}
}
},
"required": [
"code",
"language",
"timeoutMs"
],
"additionalProperties": false
}Output schema
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"language": {
"type": "string",
"enum": [
"python",
"javascript",
"typescript",
"bash"
]
},
"sandboxId": {
"type": "string"
},
"stdout": {
"type": "string"
},
"stderr": {
"type": "string"
},
"text": {
"type": [
"string",
"null"
]
},
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"isMainResult": {
"type": "boolean"
},
"text": {
"type": "string"
},
"html": {
"type": "string"
},
"markdown": {
"type": "string"
},
"json": {
"type": "string"
}
},
"required": [
"isMainResult"
],
"additionalProperties": false
}
},
"error": {
"anyOf": [
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"value": {
"type": "string"
},
"traceback": {
"type": "string"
}
},
"required": [
"name",
"value",
"traceback"
],
"additionalProperties": false
},
{
"type": "null"
}
]
},
"executionMs": {
"type": "number",
"minimum": 0
},
"provider": {
"type": "string",
"const": "e2b"
},
"tier": {
"type": "string",
"const": "hobby_sandbox"
}
},
"required": [
"language",
"sandboxId",
"stdout",
"stderr",
"text",
"results",
"error",
"executionMs",
"provider",
"tier"
],
"additionalProperties": false
}Category: Code Execution & Sandboxes · hierarchy: primary · idempotent: no · side effects: no