Async Execution
Execute code asynchronously in a background task and poll for results later. This is useful for long-running executions where you don’t want to keep the HTTP connection open.Submit Async Execution
Headers
| Header | Type | Required | Description |
|---|---|---|---|
| X-API-Key | string | Yes | Your Sandbox API key |
| Content-Type | string | Yes | Must be application/json |
Request Body
Same as synchronous execution:Response
Response Fields
| Field | Type | Description |
|---|---|---|
| execution_id | string | Unique identifier for this execution |
| status | string | Execution status: pending, running, completed, or failed |
| created_at | string | ISO 8601 timestamp when execution was created |
| started_at | string | null | ISO 8601 timestamp when execution started |
| completed_at | string | null | ISO 8601 timestamp when execution completed |
| result | object | null | Execution result (same as synchronous response) when completed |
Get Execution Status
Poll for the status and result of an async execution.Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| execution_id | string | Yes | The execution ID returned from async execution |
Response
Pending Status
Running Status
Completed Status
Failed Status
Error Responses
404 Not Found
Examples
Submit Async Execution
Poll for Status
Python Example
Complete example using Python:JavaScript Example
Complete example using JavaScript (Node.js):Status Lifecycle
The execution goes through the following states:- pending: Execution has been queued but not started yet
- running: Execution is currently in progress
- completed: Execution finished successfully (exit code may still indicate error)
- failed: Execution failed due to timeout or system error
Best Practices
- Implement exponential backoff: Don’t poll too frequently. Start with 1-2 second intervals and increase if execution takes longer
- Set reasonable timeouts: Use longer timeouts for async executions since they run in the background
- Handle all statuses: Check for both
completedandfailedstates - Store execution IDs: Save the execution ID if you need to check results later
- Clean up completed executions: Results are stored temporarily and cleaned up after a period
Use Cases
Async execution is ideal for:- Long-running computations: Calculations that take more than a few seconds
- Batch processing: Processing multiple items sequentially
- Scheduled tasks: Fire-and-forget operations where immediate results aren’t needed
- User-submitted code: Allow users to submit code and check back later
- Load balancing: Distribute execution across time to manage system load
Comparison with Synchronous Execution
| Feature | Synchronous | Asynchronous |
|---|---|---|
| Response | Immediate with result | Immediate with execution ID |
| Connection | Keeps HTTP connection open | Returns immediately |
| Best for | Quick operations (< 30s) | Long operations (> 30s) |
| Polling | Not needed | Required to get results |
| Timeout | Client timeout risk | No client timeout |