Add template `build-v2` command that uses template SDK
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Introduce `template build-v2` command that builds templates directly
from a Dockerfile via the Template SDK and wire it into the CLI.
>
> - **CLI - Template**:
> - **New Command**: `template build-v2`
(`packages/cli/src/commands/template/build-v2.ts`)
> - Builds from Dockerfile using SDK:
`Template(...).fromDockerfile(...)` and `Template.build(...)`.
> - Options: `--dockerfile`, `--cmd`, `--ready-cmd`, `--cpu-count`,
`--memory-mb`, `--no-cache`, path via `--path`; alias `bd-v2`.
> - Validations: template name format, even `memory-mb`.
> - Auth/config: uses access token, API key, domain; streams build logs;
prints success examples.
> - **Wiring**: Add `buildV2Command` to
`packages/cli/src/commands/template/index.ts`.
> - **Release**: Changeset adds patch for `@e2b/cli`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
33578b56dfbcd76c3bb2ecf7fdf6f2cb80c3d0dd. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
This PR fixes 2 bugs that made the follow option in `e2b sbx logs` not
work:
1. `e2b sbx logs -f <id>` failed to follow because the `isRunning`
function was always returning false due to the API call being
unauthenticated if you dont have the `E2B_API_KEY` environment variable
set.
This follows the existing pattern from other API calls:
https://github.com/e2b-dev/E2B/blob/c4ce97e9b9a1809e3419d64499c1e56f9138e3d0/packages/cli/src/commands/sandbox/list.ts#L138-L152
Eventually it would make sense to handle the error here, for now just a
hotfix to fix the --follow usage
2. Once it actually followed, it never stopped following because
`isRunning` was not inside the loop and always true. Now when you kill
the sandbox follow actually stops following
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Fixes `e2b sbx logs -f` by authenticating `isRunning` and re-checking
sandbox state each loop so following works and stops when closed.
>
> - **CLI — `packages/cli/src/commands/sandbox`**:
> - **Logs follow behavior (`logs.ts`)**:
> - Re-check `isRunning(sandboxID)` inside the loop (`isSandboxRunning`)
instead of using a cached promise, ensuring follow stops when sandbox is
closed or not found.
> - **Sandbox state check auth (`utils.ts`)**:
> - Use `ensureAPIKey()` and pass `apiKey` to
`Sandbox.getInfo(getShortID(sandboxID), { apiKey })` so `isRunning` is
authenticated.
> - **Release**:
> - Changeset adds patch for `@e2b/cli` with note: fix sbx logs follow
option.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
5fbd87166b70aca7229ccc1ff8fa2c27f12b1641. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Follow up my last PR, improves DX consistency and added docs.
Changelog
- format "table" > "pretty" to match other commands (metrics, logs)
- added doc section
**Changelog**
- Added ability to pass multiple sandbox ids to "sbx kill id1 id2 id3"
- Added ability to filter sandboxes to be killed by metadata and by
state using --state, --metadata (requires --all)
- Fixed metadata parser and moved to utils
Adds a deprecated `spawn` command to the CLI, ensuring backward
compatibility and guiding users toward the preferred `create` command.
```
$ e2b sandbox
Usage: index sandbox|sbx [options] [command]
work with sandboxes
Options:
-h, --help display help for command
Commands:
connect|cn <sandboxID> connect terminal to already running sandbox
list|ls [options] list all sandboxes, by default it list only running ones
kill|kl [options] [sandboxID] kill sandbox
create|cr [options] [template] create sandbox and connect terminal to it
logs|lg [options] <sandboxID> show logs for sandbox
metrics|mt [options] <sandboxID> show metrics for sandbox
help [command] display help for command
```
```
$ sbx sp base
Warning: The 'spawn' command is deprecated and will be removed in future releases. Please use 'e2b sandbox create' instead.
Terminal connecting to template base with sandbox ID in897x2dqs7aws8h1x0in
```
Introduce beta submodule with beta features - pause and resume
Update Sandbox list to also return paused sandboxes
---------
Co-authored-by: Tomas Valenta <valenta.and.thomas@gmail.com>
- CLI spawn, connect, and logs work with and without the client part
provided
- JavaScript and Python SDKs are no longer returning IDs with client
part
## Description
Add option for a template ready check. You can specify `ready_cmd` which
will be run until it exits with code 0. Max timeout is 5 minutes. After
exit code 0, the template will be marked as ready.
If no ready command is defined, `sleep 20` is assumed when the start
command is present, and `sleep 0` when none is defined. It is also
possible to define ready command without any start command. This might
be helpful if the filesystem contains self-booted services (e.g. using
systemd).
```
ready_cmd = "echo 'Starting ready check'; sleep 40; echo 'Template is ready'"
```
This adds possibility to configure the default 20 seconds wait time for
a start command.
New documentation can be found at `/docs/sandbox-template/ready-cmd`.
## Checklist
- [x] Make sure the https://github.com/e2b-dev/infra/pull/719 is
deployed
---------
Co-authored-by: Vasek Mlejnsky <vasek@e2b.dev>
Co-authored-by: Jakub Novák <jakub@e2b.dev>