Execution
Execute Code
Execute code or commands in a session
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
Bearer token with your API key
Must be
application/jsonRequest Body
ID of the session to execute code in
JavaScript/TypeScript code to execute. Either
code or command must be provided.Shell command to run (e.g.,
bun run index.ts). Either code or command must be provided.Array of files to write before execution
Environment variables to set for this execution (max 100 variables)
Execution timeout in seconds. Default: 30, Max: 300 (5 minutes)
Working directory for execution. Default:
/workspaceStream output as Server-Sent Events. Default: false
Response
Standard output from the execution
Standard error output
Process exit code (0 = success)
Execution time in milliseconds
Peak memory usage in bytes
CPU time used in milliseconds
Whether the execution was terminated due to timeout
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 likebun 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:Process Management
Processes from previous executions stay alive:Best Practices
Set appropriate timeouts
Set appropriate timeouts
Use shorter timeouts (10-30s) for quick scripts, longer (2-5min) for complex operations like installs or tests.
Batch file writes
Batch file writes
Write all files in a single execute call rather than making multiple file write requests.
Use environment variables for secrets
Use environment variables for secrets
Pass secrets via
env parameter instead of hardcoding in code. Env vars are encrypted in transit and at rest.Monitor resource usage
Monitor resource usage
Check
memoryUsed and cpuTime in responses to optimize your code and avoid hitting limits.Handle errors gracefully
Handle errors gracefully
Check
exitCode and parse stderr to detect and handle errors properly.Limits
| Resource | Free Tier | Paid Tier | Enterprise |
|---|---|---|---|
| Execution timeout | 30s | 300s (5min) | Custom |
| Memory per execution | 1GB | 4GB | Custom |
| File size | 10MB | 50MB | Custom |
| Files per request | 100 | 1000 | Custom |
| Env variables | 100 | 500 | Custom |
Related Endpoints
Write Files
Write files separately
Kill Process
Stop running processes
List Files
See all files in session