Skip to main content
POST

Overview

Executes JavaScript/TypeScript code or shell commands in an existing session. The session’s filesystem and running processes persist between executions, enabling iterative development.

Request

string
required
Bearer token with your API key
string
required
Must be application/json

Request Body

string
required
ID of the session to execute code in
string
JavaScript/TypeScript code to execute. Either code or command must be provided.
string
Shell command to run (e.g., bun run index.ts). Either code or command must be provided.
array
Array of files to write before execution
object
Environment variables to set for this execution (max 100 variables)
integer
Execution timeout in seconds. Default: 30, Max: 300 (5 minutes)
string
Working directory for execution. Default: /workspace
boolean
Stream output as Server-Sent Events. Default: false

Response

string
required
Standard output from the execution
string
required
Standard error output
integer
required
Process exit code (0 = success)
integer
required
Execution time in milliseconds
integer
required
Peak memory usage in bytes
integer
required
CPU time used in milliseconds
boolean
required
Whether the execution was terminated due to timeout
array
Paths of files written during execution

Examples

Execute Inline Code

Execute with Multiple Files

Execute with Environment Variables

Execute Shell Command

Long-Running with Timeout

Error Responses

Execution Modes

Inline Code

Pass code directly in the request body. Best for short scripts or single-file executions.

Command Execution

Run shell commands like bun run, bun test, or bun install.

Multi-file Projects

Write multiple files atomically before execution.

Streaming Output

For long-running executions, enable streaming to receive output as it’s generated:

Package Installation

Bun automatically installs packages on import:
For explicit installation:

Process Management

Processes from previous executions stay alive:
Kill background processes:

Best Practices

Use shorter timeouts (10-30s) for quick scripts, longer (2-5min) for complex operations like installs or tests.
Write all files in a single execute call rather than making multiple file write requests.
Pass secrets via env parameter instead of hardcoding in code. Env vars are encrypted in transit and at rest.
Check memoryUsed and cpuTime in responses to optimize your code and avoid hitting limits.
Check exitCode and parse stderr to detect and handle errors properly.

Limits

Write Files

Write files separately

Kill Process

Stop running processes

List Files

See all files in session