Execute Code
Execute code in a sandboxed Docker container and wait for the result.Headers
| Header | Type | Required | Description |
|---|---|---|---|
| X-API-Key | string | Yes | Your Sandbox API key |
| Content-Type | string | Yes | Must be application/json |
Request Body
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| code | string | Yes | The code to execute |
| language | string | Yes | Programming language (see supported languages) |
| stdin | string | No | Standard input to provide to the program |
| environment | object | No | Environment variables as key-value pairs |
| timeout | integer | No | Execution timeout in seconds (default: 30, max: 300) |
| session_id | string | No | Optional session ID for tracking related executions |
Response
Response Fields
| Field | Type | Description |
|---|---|---|
| execution_id | string | Unique identifier for this execution |
| stdout | string | Standard output from the program |
| stderr | string | Standard error output from the program |
| exit_code | integer | Process exit code (0 = success) |
| execution_time | float | Execution time in seconds |
| language | string | The language that was executed |
| session_id | string | null | Session ID if provided |
Error Responses
400 Bad Request
- Invalid or unsupported language
- Invalid code syntax
- Invalid parameters
429 Too Many Requests
500 Internal Server Error
Examples
Python
JavaScript
With Standard Input
With Environment Variables
With Custom Timeout
Resource Limits
All executions are subject to the following resource limits:| Resource | Default | Maximum |
|---|---|---|
| CPU | 1 core | 2 cores |
| Memory | 512 MB | 2 GB |
| Timeout | 30 seconds | 300 seconds |
| Disk | 100 MB | 1 GB |
Security
All code executions run in isolated Docker containers with:- No network access by default
- Read-only filesystem except for temporary execution directory
- Resource limits enforced by Docker
- Automatic cleanup after execution
Rate Limiting
API requests are rate-limited by API key to prevent abuse. The default limit is 100 requests per minute. If you exceed the rate limit, you’ll receive a429 Too Many Requests error. Wait before making additional requests.
Best Practices
- Set appropriate timeouts: Use shorter timeouts for simple operations to free up resources faster
- Handle errors gracefully: Check
exit_codeandstderrfor execution errors - Use session IDs: Group related executions with
session_idfor better tracking - Clean up sessions: Call the session cleanup endpoint when done
- Monitor execution time: Track
execution_timeto optimize your code