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.
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.
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 commandtemplate.setStartCmd('npm start', waitForPort(3000))// Set custom start and ready commandtemplate.setStartCmd('npm start', 'curl -s -o /dev/null -w "200"')// Set only ready commandtemplate.setReadyCmd(waitForTimeout(10_000))
The ready command is used to determine when the sandbox is ready to accept connections.
The SDK provides helper functions for common ready command patterns:
import { waitForPort, waitForProcess, waitForFile, waitForTimeout,} from 'e2b'// Wait for a port to be availablewaitForPort(3000)// Wait for a process to be runningwaitForProcess('node')// Wait for a file to existwaitForFile('/tmp/ready')// Wait for a timeoutwaitForTimeout(10_000) // 10 seconds