Skip to main content
The Execution API enables you to interact with running sandboxes through commands, code execution, file operations, and metrics monitoring. It’s implemented by the execd daemon injected into every sandbox.

API design

The Execution API is built on REST principles with Server-Sent Events (SSE) for real-time streaming:
  • Base URL: http://<sandbox-endpoint> (obtained via sandbox.get_endpoint())
  • Authentication: X-EXECD-ACCESS-TOKEN header (automatically handled by SDKs)
  • Streaming: SSE for command output, code execution results, and metrics
The SDK abstracts the Execution API, so you typically don’t need to call it directly. Use sandbox.commands, sandbox.files, and CodeInterpreter instead.

Command execution

Execute shell commands in the sandbox with streaming output.

Foreground commands

Run commands synchronously and capture output:
Features:
  • Real-time output streaming via SSE
  • Capture stdout and stderr separately
  • Exit code available after completion
  • Custom working directory

Background commands

Launch long-running processes in detached mode:
Use cases:
  • Training ML models
  • Running web servers
  • Background data processing
  • Long-running tests

Command interruption

Interrupt running commands:

Code execution

Execute code in multiple languages with stateful sessions.

Creating contexts

A context maintains execution state across multiple code blocks:

Supported languages

The Code Interpreter supports multiple programming languages:

Stateful vs stateless execution

Variables and state persist across executions:

Execution results

Code execution returns structured results:

File operations

Manage files and directories in the sandbox.

Writing files

Reading files

File metadata

Searching files

Use glob patterns to find files:

Permissions

Change file permissions:

Directory operations

System metrics

Monitor sandbox resource usage in real-time.

Snapshot metrics

Get current resource usage:

Streaming metrics

Watch metrics in real-time via SSE:
Streaming metrics generates continuous data. Use it for monitoring dashboards or alerting, not for periodic checks.

Error handling

The Execution API returns structured errors:

Common error codes

Best practices

  • Foreground commands: Short-lived commands (< 1 min)
  • Background commands: Long-running processes (> 1 min)
  • Code execution: When you need structured output and state management
For commands with large output, process streaming data incrementally:
Delete code contexts when done to free resources:
Write multiple files in a single operation for better performance:

Command execution

Full reference for command execution endpoints

Code interpreter

Complete code execution API reference

Filesystem

File operations API reference

Examples

Practical examples using the Execution API