BuildE2EBuildE2E
DocsStart Free
SandboxesCode Sandbox
Code Sandbox Endpoints

Execute Code

Run code securely in isolated sandbox environments. Each execution runs in its own isolated subprocess inside a Kata micro-VM with no network access.
POST/v1/code-sandbox/execute
Execute code in an isolated code sandbox environment.

Request Body

ParameterTypeDescription
coderequired
stringThe code to execute in the Code Sandbox
languagerequired
"python" | "javascript"Programming language runtime to use

Example Request

curl -X POST https://api.builde2e.com/api/v1/code-sandbox/execute \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer uc-YOUR-API-KEY' \
  -d '{
    "code": "print(sum(range(1, 101)))",
    "language": "python"
  }'

Example Response

json
{
  "stdout": "Hello, World!\n",
  "stderr": "",
  "exitCode": 0,
  "executionTimeMs": 95.23,
  "memoryUsageMb": 8.45,
  "timedOut": false,
  "cost": 0.002
}

Multi-line Code with Imports

You can execute multi-line code with imports and complex logic.

Python Example

bash
curl -X POST https://api.builde2e.com/api/v1/code-sandbox/execute \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer uc-YOUR-API-KEY' \
  -d '{
    "code": "import json\nimport math\n\ndata = {\n    \"name\": \"BuildE2E\",\n    \"version\": 1,\n    \"sqrt\": math.sqrt(16)\n}\nprint(json.dumps(data, indent=2))",
    "language": "python"
  }'

JavaScript Example

curl -X POST https://api.builde2e.com/api/v1/code-sandbox/execute \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer uc-YOUR-API-KEY' \
  -d '{
    "code": "const data = [3,1,4,1,5,9]; console.log(JSON.stringify(data.sort((a,b) => a-b)));",
    "language": "javascript"
  }'

Example Response

json
{
  "stdout": "{\n  \"name\": \"BuildE2E\",\n  \"version\": 1,\n  \"sqrt\": 4.0\n}\n",
  "stderr": "",
  "exitCode": 0,
  "executionTimeMs": 142.56,
  "memoryUsageMb": 9.12,
  "timedOut": false,
  "cost": 0.002
}

Using the SDK

The Node.js SDK provides a simple interface for code execution:
javascript
import BuildE2E from '@builde2e/sdk';

BuildE2E.setApiKey('uc-YOUR-API-KEY');

// Python
const pyResult = await BuildE2E.executeCode({
  code: 'import numpy as np; print(np.array([1, 2, 3]))',
  language: 'python'
});

// JavaScript
const jsResult = await BuildE2E.executeCode({
  code: 'const _ = require("lodash"); console.log(_.chunk([1,2,3,4], 2));',
  language: 'javascript'
});

console.log(pyResult.stdout);          // "[1 2 3]\n"
console.log(jsResult.stdout);          // "[ [ 1, 2 ], [ 3, 4 ] ]\n"
console.log(pyResult.memoryUsageMb);   // 30.5

Response Fields

FieldTypeDescription
stdoutstringStandard output from the code execution
stderrstringStandard error output from the code execution
exitCodenumberExit code (0 = success, 124 = timeout)
executionTimeMsnumberTime taken to execute the code in milliseconds
memoryUsageMbnumberPeak memory usage during execution in megabytes
timedOutbooleanWhether the execution timed out
errorstringError message if execution infrastructure failed
costnumberCost of the request in USD

Pre-installed Libraries

The following libraries are pre-installed and ready to use. No installation or network access is needed.

Python

Python 3.12 with the full standard library, plus:
numpypandassympypython-dateutilPillow

JavaScript

Node.js 22 with CommonJS modules (require() syntax), plus:
lodashdayjsmathjs

Pricing

Each code execution costs $0.002 USD (~$2.00 per 1000 executions). Cost is charged regardless of whether the code succeeds or fails.

Execution Limits

Code Sandbox executions have the following limits to ensure fair usage:
LimitValueDescription
Timeout10 secondsMaximum execution time before timeout
Memory256 MBMaximum memory allocation per execution
CPU0.5 coresCPU allocation per execution
Code size100 KBMaximum size of submitted code
Output1 MBMaximum stdout/stderr output size
NetworkNoneNo network access from sandbox

Error Handling

When code execution fails, the response will contain error information:
json
{
  "stdout": "",
  "stderr": "Traceback (most recent call last):\n  File "<string>", line 1, in <module>\nZeroDivisionError: division by zero",
  "exitCode": 1,
  "executionTimeMs": 45.12,
  "memoryUsageMb": 6.78,
  "timedOut": false,
  "cost": 0.002
}
When execution times out (exceeds 10 seconds):
json
{
  "stdout": "",
  "stderr": "",
  "exitCode": 124,
  "executionTimeMs": 10000,
  "memoryUsageMb": 12.34,
  "timedOut": true,
  "cost": 0.002
}