Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mlejva committed Nov 24, 2023
1 parent 01d86b9 commit d487184
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
51 changes: 37 additions & 14 deletions apps/docs/src/app/sandbox/templates/start-cmd/page.mdx
Original file line number Diff line number Diff line change
@@ -1,29 +1,55 @@
# Start Command
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.

Custom sandboxes allow you to specify a command that will be running when a sandbox is spawned.
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.

This way you can run a command that will start your app, or run a command that will start a specific process.
## How it works
When building a custom sandbox, we create a container based on your [`e2b.Dockerfile`](/sandbox/templates/template-file) file.
We extract the container's filesystem and start a sandbox with this extracted filesystem.
We call this sandbox a _template sandbox_. Now two things can happen depending whether you specified the start command or not.

- **If you don't specify the start command**
1. we take the running template sandbox
1. snapshot it and make it ready for you to spawn it with the SDK

## How to add a start command
- **If you do specify the start command**
1. we take the running template sandbox
1. **execute the start command and wait 15 seconds**
1. snapshot it and make it ready for you to spawn it with the SDK


<Note title="Sandbox Snapshot">
Snapshots are saved running sandboxes. We serialize and save the whole sandbox's filesystem together with all the running processes in a way that can be loaded later.

This allows us to load the sandbox in a few hundred milliseconds any time later with all the processes already running and the filesystem exactly as it was.
</Note>


## Limits
- The network isn't accessible when running the start command.
- We wait 15 seconds after we execute the start command before we snapshot the sandbox.


## How to add start command

When you are building a sandbox template you can specify the start command by using the [`-c`](/cli/commands#build) option:

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

After the sandbox template is built, when you spawn a sandbox the start command will be running if there was no error when it tried to start.

You can check the logs from the start command by using the SDKs:
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.

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

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

// Spawn your custom sandbox
const sandbox = await Sandbox.create({
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.
Expand Down Expand Up @@ -53,17 +79,14 @@ sandbox.close()
</CodeGroup>


### Sandbox template config


You can find the start command for the sandbox template in the `e2b.toml`:

## Sandbox template config
The start command is specified inside the `e2b.toml` in the same directory where you ran `e2b build -c "<your-start-command>"`.
<CodeGroup isFileName title="e2b.toml" isRunnable={false}>
```toml
# This is a config for E2B sandbox template
id = "1wdqsf9le9gk21ztb4mo"
dockerfile = "e2b.Dockerfile"
name = "my-agent-sandbox"
start_cmd = "npm start" # $HighlightLine
start_cmd = "<your-start-command>" # $HighlightLine
```
</CodeGroup>
18 changes: 9 additions & 9 deletions apps/docs/src/components/Navigation/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,33 +161,33 @@ export const routes = [
},
{
icon: (
<Hammer
<PlaySquare
strokeWidth={1}
size={20}
/>
),
title: 'Guide: Creating Custom Sandbox',
href: '/guide/custom-sandbox',
title: 'Start Command',
href: '/sandbox/templates/start-cmd',
},
{
icon: (
<PlaySquare
<Boxes
strokeWidth={1}
size={20}
/>
),
title: 'Start Command',
href: '/sandbox/templates/start-cmd',
title: 'Premade Sandboxes',
href: '/sandbox/templates/premade',
},
{
icon: (
<Boxes
<Hammer
strokeWidth={1}
size={20}
/>
),
title: 'Premade Sandboxes',
href: '/sandbox/templates/premade',
title: 'Guide: Creating Custom Sandbox',
href: '/guide/custom-sandbox',
},
]
},
Expand Down

1 comment on commit d487184

@vercel
Copy link

@vercel vercel bot commented on d487184 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

e2b-docs – ./apps/docs

e2b-docs-e2b.vercel.app
e2b-docs.vercel.app
e2b-docs-git-main-e2b.vercel.app

Please sign in to comment.