# minisandbox.yaml

Every field of a template recipe, its rules and its defaults.

A template is built from a `minisandbox.yaml` recipe. This page lists every field `ons` and the API accept. For a walkthrough, read [Templates](https://onshore.sh/docs/guides/templates).

```yaml minisandbox.yaml
version: 1
name: web-app
from: dev-base
resources:
  vcpu: 2
  memory: 4GiB
  disk: 16GiB
workdir: /home/user/app
files:
  - src: .
    dest: /home/user/app
    ignore: [node_modules, .git, "*.log"]
env:
  NODE_ENV: development
setup:
  - curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
  - sudo apt-get install -y nodejs
  - npm ci
start:
  cmd: npm run dev
  ready:
    http: http://localhost:3000/
    timeout: 2m
on_start:
  - git pull --ff-only || true
egress:
  presets: [ubuntu, npm, github]
  allow:
    - deb.nodesource.com
ports: [3000]
```

## Format rules

- The file is at most 256 KiB, nested at most 32 levels.
- YAML anchors, aliases and tags are refused. Write values out in full.
- Duplicate keys and unknown fields are refused.
- `ons` reports every problem in one pass, each with its file, line and column, and the fix:

```text
minisandbox.yaml:12:3: unknown field `setpu` · did you mean `setup`?
minisandbox.yaml:4:1: `from`, `image` and `dockerfile` are exclusive · keep one
```

**Sizes** take a binary unit: `KiB`, `MiB`, `GiB` or `TiB` (`512MiB`, `8GiB`). **Durations** take `s`, `m` or `h` (`90s`, `10m`, `2h`).

## Fields

### `version`

Required. Always `1`.

### `name`

Required. The template's name in your organization: lowercase letters, digits and dashes, starting with a letter or a digit, 63 characters at most. You start miniVMs from it with `ons create --template <name>`.

### `from`, `image`, `dockerfile`

Exactly one is required. It sets what the template starts from.

| Field        | Value                                                                                                                                                          |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `from`       | A template of your organization, or a base template: `dev-base`, `dev-agents`.                                                                                 |
| `image`      | An OCI image reference from a public registry, such as `ghcr.io/<org>/<image>:<tag>` or `<name>@sha256:<digest>`. A tag is resolved to a digest at build time. |
| `dockerfile` | A path to a Dockerfile, relative to the recipe and inside its directory. That directory is the build context.                                                  |

With `from`, the template inherits the base's disk and its resolved `env`. It does **not** inherit the base's `resources`, `egress`, `ports` or `start`: write the ones you need in your recipe.

With `dockerfile`:

- A `.dockerignore` next to the Dockerfile trims the context (same syntax as `ignore` below; `!` exceptions are refused).
- A `# syntax=` line (a custom BuildKit frontend) is refused.
- `ons` warns when the context holds `.git` or a `.env*` file, which a `COPY . .` would freeze into every snapshot.

`devcontainer` is refused for now: use `dockerfile`.

### `resources`

The size of every miniVM of the template. A field you leave out takes the default below, never the base template's.

| Field    | Default | Rule                               |
| -------- | ------- | ---------------------------------- |
| `vcpu`   | `2`     | `1` or an even number up to `32`.  |
| `memory` | `2GiB`  | At least `128MiB`.                 |
| `disk`   | `8GiB`  | Must hold the image plus `512MiB`. |

Your organization's limits cap what a create may ask for. On the managed service, a miniVM has at most 8 vCPU and 16 GiB of memory today. See [Quotas and limits](https://onshore.sh/docs/account/quotas-and-limits).

### `user`

The user that runs `setup`, `start` and `on_start`, and the commands and file calls of an SDK that names no user. Default `user`. When the image already has this account, the build uses it as is. When it does not, the build creates it with uid 1000, home `/home/<user>` and passwordless `sudo`. If uid or gid 1000 is already taken in the image (`ubuntu:24.04` has `ubuntu`), the build fails and says what to set instead: an account of the image, or `root`. With `user: root`, no other account is created. Lowercase letters, digits, `_` and `-`, 32 characters at most.

### `workdir`

An absolute path, created if missing and owned by `user`. Default `/home/<user>`, or `/root` for `root`.

### `files`

Files copied from your machine into the template at build time. A list of:

| Field    | Rule                                                                                                                                                         |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `src`    | Relative to the recipe's directory and inside it. `.` is the directory itself.                                                                               |
| `dest`   | An absolute path in the template.                                                                                                                            |
| `ignore` | Optional. Names skipped at any depth (`node_modules`, `*.log`) or paths from `src` (`dist/cache`). `*` and `?` match inside one name. At most 1000 patterns. |

Symlinks are copied as links and never followed. What lands under the user's home or `workdir` belongs to `user`; anything else belongs to root. The packed context is at most 2 GiB and 100 000 entries.

### `env`

Environment variables for `setup`, `start`, `on_start` and every miniVM of the template.

```yaml
env:
  NODE_ENV: production
  LOG_LEVEL: info
```

- Names use uppercase letters, digits and `_`, and do not start with a digit.
- The prefixes `MSB_` and `E2B_` are reserved.
- A value is at most 32 KiB. All variables together, with the base's: at most 1024 variables and 128 KiB.
- With `from`, your names override the base's one by one, without interpolation: a `PATH` here replaces the base's `PATH` whole.

> **Warning:** `env` is stored in plain text, in the recipe and in every snapshot of the template. Never put a secret in `env`, `files`, `setup` or a Dockerfile `ARG`. See [Secrets](#secrets).

### `setup`

Shell lines run once, at build, in order. Each runs through `bash -lc` as `user`, in `workdir`, with `env` and the template's `egress`. A non-zero exit fails the build. An empty line is refused.

### `start`

Optional. A long-running process started after `setup` and kept alive in the snapshot, so each miniVM starts with it already running.

```yaml
start:
  cmd: npm start
  ready:
    http: http://localhost:3000/health
    timeout: 90s
```

| Field           | Rule                                                                         |
| --------------- | ---------------------------------------------------------------------------- |
| `cmd`           | The command. It must stay in the foreground: `npm start &` fails the build.  |
| `ready`         | Required. Exactly one of `http`, `tcp` or `cmd`, plus an optional `timeout`. |
| `ready.http`    | A plain `http://localhost…` URL (or `127.0.0.1`, `[::1]`) that answers 2xx.  |
| `ready.tcp`     | A port that accepts connections.                                             |
| `ready.cmd`     | A command that exits 0 once the process is ready.                            |
| `ready.timeout` | Default `60s`, at most `10m`.                                                |

### `on_start`

Shell lines run in the background after each start of a miniVM from the template, as `user` in `workdir`. A create does not wait for them.

### `egress`

Outbound network access. **Closed when absent.** It applies to `setup`, `start` and every miniVM of the template.

```yaml
egress:
  presets: [github, npm]
  allow:
    - api.example.com
    - "*.example.org"
```

| Field     | Rule                                                                                              |
| --------- | ------------------------------------------------------------------------------------------------- |
| `presets` | Named lists of domains, below.                                                                    |
| `allow`   | Lowercase domains of two labels or more, optionally starting with `*.`. IP addresses are refused. |

At most 256 domains in total, presets expanded.

| Preset       | Domains                                                                                                                                                                                                                 |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `github`     | `github.com`, `api.github.com`, `codeload.github.com`, `uploads.github.com`, `raw.githubusercontent.com`, `objects.githubusercontent.com`, `release-assets.githubusercontent.com`, `github-cloud.githubusercontent.com` |
| `npm`        | `registry.npmjs.org`, `registry.yarnpkg.com`, `repo.yarnpkg.com`, `nodejs.org`                                                                                                                                          |
| `pypi`       | `pypi.org`, `files.pythonhosted.org`                                                                                                                                                                                    |
| `crates`     | `crates.io`, `index.crates.io`, `static.crates.io`, `static.rust-lang.org`                                                                                                                                              |
| `ubuntu`     | `archive.ubuntu.com`, `*.archive.ubuntu.com`, `security.ubuntu.com`, `ports.ubuntu.com`, `snapshot.ubuntu.com`                                                                                                          |
| `docker-hub` | `registry-1.docker.io`, `auth.docker.io`, `index.docker.io`, `production.cloudflare.docker.com`, `production.cloudfront.docker.com`                                                                                     |
| `ghcr`       | `ghcr.io`, `pkg-containers.githubusercontent.com`                                                                                                                                                                       |
| `llm-apis`   | `api.anthropic.com`, `api.openai.com`, `platform.claude.com`, `claude.ai`, `generativelanguage.googleapis.com`, `api.mistral.ai`, `openrouter.ai`, `opencode.ai`, `models.dev`                                          |

A create can narrow or widen this list for one miniVM, and you can change it while the miniVM runs. More in [Egress](https://onshore.sh/docs/guides/egress).

### `ports`

Ports of the miniVM you can open as preview URLs. Port 0 and 49983 (reserved for the miniVM's agent) are refused, and a port may be listed once. See [Processes, files and ports](https://onshore.sh/docs/guides/processes-files-ports).

### `lifecycle`

```yaml
lifecycle:
  timeout: 2h
  idle:
    after: 15m
    action: pause
```

| Field         | Rule                 |
| ------------- | -------------------- |
| `timeout`     | A positive duration. |
| `idle.after`  | A positive duration. |
| `idle.action` | `pause` or `kill`.   |

> **Note:** `lifecycle` is validated and recorded with the template version, but it does not change miniVMs yet. Set the timeout and auto-pause when you create the miniVM. See [Lifecycle](https://onshore.sh/docs/guides/lifecycle).

### `placement`

```yaml
placement:
  pool: <pool-name>
```

`<pool-name>` is a pool of your organization (lowercase letters, digits and dashes). miniVMs of the template are placed there. You only need it with [miniVMs on your own servers](https://onshore.sh/docs/guides/hybrid).

### Secrets

A recipe never holds a secret value. The `secrets` field is refused for now (`secrets are not supported yet`). Pass secret values when you create a miniVM instead:

- as environment variables of the create, with the E2B SDK (`envs` of `Sandbox.create`);
- as egress credentials, which the platform adds to the miniVM's outbound requests without the miniVM ever seeing them. See [Egress](https://onshore.sh/docs/guides/egress).

`setup` and `start` run without any secret, so no snapshot holds one.

## Check a recipe

```bash
ons template validate
ons template build --dry-run
```

Both run offline. `--dry-run` also prints the digests the build would use. Pass `--file <path>` for a recipe that is not `./minisandbox.yaml`.

Markdown version: https://onshore.sh/docs/reference/minisandbox-yaml.md
