# Environment variables

Env vars are encrypted at rest (AES-256-GCM) and injected at container startup. Changes take effect on the next deploy.

```sh
bunx percher env set STRIPE_KEY=sk_live_...
bunx percher env set --from-env-file .env   # every KEY=VALUE line at once
bunx percher env list          # values are masked
bunx percher env unset STRIPE_KEY
```

**Bulk import.** `env set --from-env-file .env` sets every KEY=VALUE line from a .env-format file in one call (comments, quotes, and `export` prefixes handled; the file is only read when you pass the flag — never automatically). The dashboard env editor has the same thing: "Paste a .env file" shows a preview with conflict badges before anything is saved.

**Deploy scopes.** Every var has a scope: unscoped (default) applies everywhere; `--scope preview` applies only to preview deploys (all four preview kinds) and overrides the unscoped value there; `--scope live` does the reverse. So `percher env set DATABASE_URL=postgres://staging... --scope preview` keeps every preview away from the production database while live keeps the unscoped value. `env list` annotates scoped rows; unset is scope-specific (`env unset KEY --scope preview` leaves the live value alone). The env-requirement gate is scope-aware too — a preview-only key never satisfies a live deploy's requirements. Three keys can't be scoped: `SITE_PASSWORD` (the login gate reads one password per app, live and previews alike) and the PocketBase admin credentials (platform-managed).

**Build-time exposure.** Keys matching a public prefix (`NEXT_PUBLIC_*`, `VITE_*`, `NUXT_PUBLIC_*`, `PUBLIC_*`, `REACT_APP_*`, `VUE_APP_*`, `EXPO_PUBLIC_*`) are forwarded to the build automatically and baked into the client bundle — the dashboard shows a "build + runtime" chip on those keys. Everything else is runtime-only (correct for secrets), which breaks frameworks that expect a non-prefix value at build time; opt those in per key via `[build] pass_env` in percher.toml. Values always come from the env store, not the TOML. For `runtime = "docker"`, legacy private `pass_env` values still arrive as build arguments and can persist in image history and cache; deploys warn until you migrate. Replace each private `ARG`/`ENV` consumer with `RUN --mount=type=secret,id=KEY,env=KEY,required=true <command>`, using the actual key name, then add `# percher: build-secrets=mount` after all parser directives, before the first instruction. Keep the keys in `[build] pass_env` and their values in the env store. Mount every consuming step; never print or save values. Percher leaves your Dockerfile unchanged and does not prove its commands safe. Fresh mounted builds skip Docker layer reuse; identical source and secret values may reuse the complete image cache.

**Finish the Dockerfile migration.**
1. If a token may already have reached old layers or history, rotate or revoke it at its issuer, coordinating with your app's use of it. Set its replacement with `bunx percher env set KEY` (hidden prompt), using the intended app and deploy scope.
2. From the edited project, run `bunx percher publish` (agents: `percher_publish`). Redeploy reuses uploaded source and does not upload your Dockerfile changes.
3. Wait for successful deployment completion (agents follow the returned `percher_wait_for_deploy` recovery). In the dashboard, open this app's Publishes, select Deploys & previews, and expand that deployment. Resolve any `build-secret-policy` warning in its build problems. Agents can inspect `deploy.problems` with `percher_deploys_inspect`. CLI output is only a log tail; unavailable diagnostics or absence of the warning alone do not verify migration.

Old images, caches and history remain; a pinned rollback can reuse a legacy image, so review that target before using it.

**Outbound HTTPS.** Apps run on an internal Docker network and reach the public internet through a forward proxy Percher injects automatically: `HTTP_PROXY`/`HTTPS_PROXY=http://egress-proxy:8888`, `NO_PROXY=localhost,127.0.0.1,.local`, `NODE_USE_ENV_PROXY=1`. Bun and Node 22.21+/24+ use it automatically; Python (requests/httpx/urllib) and Go honor `HTTPS_PROXY` natively; Node 20 and the 21/23 lines need `setGlobalDispatcher(new ProxyAgent(process.env.HTTPS_PROXY))` from undici at startup. Direct outbound is blocked by design, so `ENETUNREACH` on `1.1.1.1:443` means the runtime isn't using the proxy. There is no host allowlist, but proxied HTTPS is port 443 only — an `https://host:8443` URL gets a 403 from the proxy.

Full guide: https://percher.app/docs/env-vars
