> ## Documentation Index
> Fetch the complete documentation index at: https://e2b-mintlify-changelog-1774264263.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Start & ready commands

> Define running processes for the sandbox

## 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](#ready-command) to confirm the process is up, and then takes a [snapshot](/docs/template/how-it-works) 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.

<Note title="The start command does not run on sandbox creation">
  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()`](/docs/sandbox/environment-variables#1-global-environment-variables) 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()`.
</Note>

You can see the full build process [here](/docs/template/how-it-works).

## Ready command

The ready command allows you to specify a command that will determine **template sandbox** readiness before a [snapshot](/docs/template/how-it-works) 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](/docs/template/start-ready-command#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):

<CodeGroup>
  ```typescript JavaScript & TypeScript theme={null}
  // 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))
  ```

  ```python Python theme={null}
  # Set both start command and ready command
  template.set_start_cmd("npm start", wait_for_port(3000))

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

  # Set only ready command
  template.set_ready_cmd(wait_for_timeout(10_000))
  ```
</CodeGroup>

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:

<CodeGroup>
  ```typescript JavaScript & TypeScript theme={null}
  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
  ```

  ```python Python theme={null}
  from e2b import wait_for_port, wait_for_process, wait_for_file, wait_for_timeout

  # Wait for a port to be available
  wait_for_port(3000)

  # Wait for a process to be running
  wait_for_process("node")

  # Wait for a file to exist
  wait_for_file("/tmp/ready")

  # Wait for a specified duration
  wait_for_timeout(10_000) # 10 seconds
  ```
</CodeGroup>
