Skip to content
Start and Ready Commands

Start Command and Readiness Command

The start command runs automatically when the sandbox starts, and the readiness command checks whether the sandbox is fully ready.

Start Command

The start command runs when the template sandbox starts for the first time. These commands execute during template building and complete before the sandbox snapshot is taken.

Readiness Command

The readiness command checks whether the sandbox is fully ready and usable. This command runs in an infinite loop until it returns exit code 0. This ensures that all services are fully started before users connect to the sandbox.

Usage

javascript
import { Template, waitForPort } from '@e2b/code-interpreter'

const template = Template()
  .fromBaseImage()
  .setStartCmd('python -m http.server 8000')
  .setReadyCmd(waitForPort(8000))

// Or use custom ready check
const template2 = Template()
  .fromBaseImage()
  .setStartCmd('redis-server --daemonize yes')
  .setReadyCmd('redis-cli ping')

// Or only ready command
const template3 = Template()
  .fromBaseImage()
  .setReadyCmd('curl http://localhost:3000')

Readiness Command Helper Functions

The SDK provides commonly used readiness check helper functions:

javascript
import {
  Template,
  waitForPort,
  waitForProcess,
  waitForFile,
  waitForTimeout
} from '@e2b/code-interpreter'

const template = Template().fromBaseImage()

// Wait for port to be available
template.setReadyCmd(waitForPort(3000))

// Wait for process to be running
template.setReadyCmd(waitForProcess('node'))

// Wait for file to exist
template.setReadyCmd(waitForFile('/tmp/ready'))

// Wait for timeout
template.setReadyCmd(waitForTimeout(10_000)) // 10 seconds