> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zode.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Environments and secrets

> Manage environments, their variables and their secrets with zode env and zode secret. Secret values are read from stdin, never the command line.

An environment is a named set of variables and secrets that sandboxes read. Every workspace has one called `default`. Background: [Environments and secrets](https://docs.zode.dev/concepts/environments-and-secrets.md).

Wherever a command takes `--env ENV`, ENV is an environment name or `env_` id, and leaving it out means `default`. `--environment` is the same flag. Making and deleting environments, and setting variables and secrets, needs an owner or admin.

## zode env

```bash theme={null}
zode env ls                                  # list environments
zode env create <name>                       # make one
zode env rm <env>                            # delete one (not default)
zode env vars [--env ENV]                    # list variables and their values
zode env set KEY=VALUE [...] [--env ENV]     # set variables
zode env unset KEY [...] [--env ENV]         # delete variables
```

`zode envs`, `zode environment` and `zode environments` work too.

```bash theme={null}
zode env create staging
```

```text theme={null}
staging created (env_m4kq2xrt7vbn3wda)
  zode env set KEY=VALUE --env staging
  zode secret set NAME --host H --env staging
```

```bash theme={null}
zode env set APP_ENV=staging LOG_LEVEL=debug --env staging
zode env vars --env staging
```

```text theme={null}
set APP_ENV, LOG_LEVEL in staging
APP_ENV=staging
LOG_LEVEL=debug
```

```bash theme={null}
zode env ls
```

```text theme={null}
NAME     VARIABLES  SECRETS  ID
default  0          1        env_p7wd3kq2mxvt6bna
staging  2          0        env_m4kq2xrt7vbn3wda
```

Variables are plain values that every sandbox in the environment sees. Put anything sensitive in a secret instead. To make a sandbox read an environment, pass `--environment` to [`zode new`](https://docs.zode.dev/cli/sandboxes#make); a fork reads its parent's.

### Private network and mesh

```bash theme={null}
zode env network <env>                                # its private network and mesh connection
zode env network <env> [--cidr C] [--domains a,b]     # change them
zode env mesh <env> tailscale [--oauth-client-id ID]
zode env mesh <env> headscale --control-url URL
zode env mesh <env> netbird [--control-url URL] [--api-token]
zode env mesh <env> off                               # disconnect it
```

These take the environment as a positional argument, not `--env`. Read [How private networking works](https://docs.zode.dev/networking/private-networking.md) first, then the page for your mesh: [Tailscale](https://docs.zode.dev/networking/tailscale.md), [Headscale](https://docs.zode.dev/networking/headscale.md) or [NetBird](https://docs.zode.dev/networking/netbird.md).

* `zode env network <env>` shows the environment's private range, the DNS domains that resolve through the mesh, the mesh connection, and one row per host router (`ROUTER`, `ONLINE`, `ROUTES`, `SANDBOXES`, `ERROR`).
* `--cidr` sets the private `/16` the environment's sandboxes get. `--domains` sets the DNS names that resolve through the mesh, comma separated; `--domains ""` clears them.
* `zode env mesh` reads every credential from stdin, or asks for it without echo: a reusable tagged auth key for Tailscale or Headscale, or the OAuth client secret when you pass `--oauth-client-id`; a reusable setup key for NetBird, and a NetBird API token too with `--api-token`, so Zode can add the routes itself. `--control-url` is your Headscale server, or a self-hosted NetBird management URL.
* On success it prints `staging is on your tailscale mesh as 10.77.0.0/16; routers come up on its nodes now (zode env network staging)`, then the lines to add to your tailnet policy, or the routes to add in NetBird.

## zode secret

```bash theme={null}
zode secret ls [--env ENV]                              # list secrets, never values
zode secret set NAME --host H [--host H ...] [--env ENV] [--unverified]
zode secret allow NAME HOST [--env ENV]                 # let it reach one more host
zode secret rm NAME [--env ENV]                         # delete it
```

`zode secrets` works too, and `add` for `set`, `delete` for `rm`.

A sandbox never sees a secret's value. It gets a placeholder, and the host's egress proxy swaps in the real value only on requests to the secret's hosts. Hosts are names such as `api.stripe.com`, or `*.example.com` for any subdomain.

### Set a secret

The value never goes on the command line, where shell history and `ps` would keep it. Pipe it in, or type it at the prompt, which does not echo:

```bash theme={null}
printf %s "$STRIPE_KEY" | zode secret set STRIPE_KEY --host api.stripe.com
zode secret set OPENAI_API_KEY --host api.openai.com --env staging
```

```text theme={null}
Value for OPENAI_API_KEY (not shown):
OPENAI_API_KEY is set in staging for api.openai.com
  sandboxes see a placeholder; the real value is sent only to those hosts
```

One trailing newline in piped input is dropped. A value is at most 16 KB. `--host` is required at least once; repeat it for more hosts. Setting an existing name replaces its value and hosts.

### Host check before upload

Before it uploads a value, `zode secret set` checks the signed release of every host in the regions your workspace runs in, on your machine, the same way as [`zode verify`](https://docs.zode.dev/cli/verify). It does not take the API's word for it.

If any host does not verify, nothing is uploaded:

```text theme={null}
zode: not uploading STRIPE_KEY: 2 of 2 hosts in eu-central do not run a signed Zode release (zode verify eu-central shows why). Pass --unverified to upload it anyway
```

`--unverified` uploads anyway and says so on stderr. When every host verifies but some are `signed_image` rather than `tpm_quoted`, the CLI uploads and prints a note: the release is in the public log, but those hosts' measurements are their own word, not a TPM quote. See [Attestation](https://docs.zode.dev/concepts/attestation.md).

Some credentials cannot be swapped by a proxy and are refused with `secret_unsupported`, for example AWS secret keys and database connection strings. See [Limits](https://docs.zode.dev/concepts/environments-and-secrets.md#limits).

### List, allow, delete

```bash theme={null}
zode secret ls --env staging
```

```text theme={null}
NAME            HOSTS           UPDATED  LAST USED
OPENAI_API_KEY  api.openai.com  2m ago   never
STRIPE_KEY      api.stripe.com  1h ago   5m ago
2 in staging
```

`LAST USED` is when a host last swapped the value into a request.

```bash theme={null}
zode secret allow STRIPE_KEY files.stripe.com
```

```text theme={null}
STRIPE_KEY now reaches api.stripe.com, files.stripe.com
```

`allow` keeps the stored value and changes only the hosts, so it does not ask for the value or run the host check.

```bash theme={null}
zode secret rm STRIPE_KEY
```

```text theme={null}
deleted STRIPE_KEY from default
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.