# 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](/docs/sandbox-template#how-it-works).

## How to add start command

When you are building a sandbox template you can specify the start command by using the [`-c`](/docs/sdk-reference/cli/v1.0.9/template#e2b-template-build) option:

```bash
e2b template build -c "<your-start-command>"
```

When you spawn the custom sandbox you built, the start command will be already running if there was no error when we tried to execute it.

### Sandbox template config
You can specify the start command also inside the `e2b.toml` in the same directory where you run `e2b template build`.
<CodeGroup isFileName title="e2b.toml" isRunnable={false}>
  ```toml
  # This is a config for E2B sandbox template
  template_id = "1wdqsf9le9gk21ztb4mo"
  dockerfile = "e2b.Dockerfile"
  template_name = "my-agent-sandbox"
  start_cmd = "<your-start-command>"  # $HighlightLine
  ```
</CodeGroup>


## Logs
You can retrieve the start command's logs using the SDK during runtime.

<Note>
These logs are the logs from the start command during the build phase.
</Note>

<CodeGroup title="Check start command logs" isRunnable={false}>
```js {{ language: 'js' }}
import { Sandbox } from 'e2b'

// Spawn your custom sandbox
const sandbox = await Sandbox.create({
  id: 'my-agent-sandbox',
  // If you specify onStderr and onStdout handlers when spawning the sandbox
  // you will see logs from the start command.
  onStderr: output => console.log("stderr", output.line), // $HighlightLine
  onStdout: output => console.log("stdout", output.line), // $HighlightLine
})

// Close sandbox once done
await sandbox.close()
```

```python {{ language: 'python' }}
from e2b import Sandbox

# Spawn your custom sandbox
sandbox = Sandbox(
  id="my-agent-sandbox",
  # If you specify on_stderr and on_stdout handlers when spawning the sandbox
  # you will see logs from the start command.
  on_stderr=lambda output: print("stderr", output.line),  # $HighlightLine
  on_stdout=lambda output: print("stdout", output.line),  # $HighlightLine
)

# Close sandbox once done
sandbox.kill()
```
</CodeGroup>

Or you can use the CLI:

<CodeGroup isTerminalCommand>
```bash {{ language: 'bash' }}
e2b sandbox logs <sandbox-id>
```
</CodeGroup>
