Skip to main content

Start command

The start command lets you specify a process that runs at the end of the template build — not when a sandbox is created. During the build, E2B executes the start command, waits for the ready command to confirm the process is up, and then takes a snapshot of the entire sandbox including the running process. When you later create a sandbox from that template, the snapshotted process is already running — there is no startup wait. This is how you get servers, seeded databases, or any long-running process available instantly when spawning sandboxes with the SDK.
The start command runs once during template build and is captured in a snapshot. It does not re-execute each time you create a sandbox. If you need to run a command every time a sandbox is created, use sandbox.commands.run() after creating the sandbox instead.This also means that environment variables passed to Sandbox.create() are not available to the start command process — it already ran during the build. If your start command needs environment variables, set them in the template definition using setEnvs() / set_envs().
You can see the full build process here.

Ready command

The ready command allows you to specify a command that will determine template sandbox readiness before a snapshot is created. It is executed in an infinite loop until it returns a successful exit code 0. This way you can control how long should we wait for the start command or any system state.

Usage

Set the start command (executed during template build) and the ready command (determines when the process is up before snapshotting):
// Set both start command and ready command
template.setStartCmd('npm start', waitForPort(3000))

// Set custom start and ready command
template.setStartCmd('npm start', 'curl -s -o /dev/null -w "200"')

// Set only ready command
template.setReadyCmd(waitForTimeout(10_000))
The ready command is used to determine when the sandbox is ready to accept connections.

Ready command helpers

The SDK provides helper functions for common ready command patterns:
import {
  waitForPort,
  waitForProcess,
  waitForFile,
  waitForTimeout,
} from 'e2b'

// Wait for a port to be available
waitForPort(3000)

// Wait for a process to be running
waitForProcess('node')

// Wait for a file to exist
waitForFile('/tmp/ready')

// Wait for a timeout
waitForTimeout(10_000) // 10 seconds