Skip to main content

Start command

The start command allows you to specify a command that will be already running when you spawn your custom sandbox. This way, you can for example have running servers or seeded databases inside the sandbox that are already fully ready when you spawn the sandbox using the SDK and with zero waiting time for your users during the runtime. The idea behind the start command feature is to lower the wait times for your users and have everything ready for your users when you spawn your sandbox. You can see how it works 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 command that runs when the sandbox starts and the command that determines when the sandbox is ready:
// Set both start command and ready command
template.setStartCmd('npm start', waitForPort(3000))

// Set only ready command
template.setReadyCmd(waitForTimeout(10_000))
The ready command is used to determine when the sandbox is ready to accept connections.
You can only call these commands once per template. Subsequent calls will throw an error.

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
I