# Environment variables and secrets

> Values per environment, secrets encrypted with your project's key, build-time values and deploy tokens.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://run.docs.sypnia.com/config/environment-and-secrets/

For agents: Run environment variables and secrets: per environment (production, preview, development, custom), snapshot per deploy; commands env set [--secret] [--build], env ls, env pull; secrets encrypted with a per-project KMS key in SSM Parameter Store, never shown again, masked in logs, not written to artifacts; public prefixes (NEXT_PUBLIC_, PUBLIC_, VITE_) refused for secrets; connected Sypnia products inject their variables; deploy tokens scoped to app+environments (shown once, hashed), GitHub Actions OIDC trust.

Variables belong to an **environment**: `production`, `preview`, `development` or one you create. A deploy takes a snapshot of its environment's variables when it is made; changing a variable affects the next deploy, never a running one, until you redeploy or run `run env apply`.

## Commands

```bash
npx @sypnia/run env set NEXT_PUBLIC_SHOP_NAME "La Espiga" --env production
npx @sypnia/run env set DATABASE_URL --secret --env production    # asked without echo
npx @sypnia/run env ls --env production                            # secrets show as ••••
npx @sypnia/run env pull --env development > .env.local            # plain values for local work; secrets only with --include-secrets and permission
```

## Plain values and secrets

|                         | Plain variable               | Secret                                                                                 |
| ----------------------- | ---------------------------- | -------------------------------------------------------------------------------------- |
| Visible after saving    | yes                          | never; only replaced or deleted                                                        |
| Stored                  | encrypted at rest            | encrypted with the project's own key (AWS KMS), in AWS Systems Manager Parameter Store |
| Available at build time | if listed in `build.env`     | only if marked `--build`, masked in logs                                               |
| Reaches your code       | in `process.env` at run time | the same, decrypted by the runtime's role, never written to the artifacts              |

Names starting with `NEXT_PUBLIC_`, `PUBLIC_` or `VITE_` are embedded in browser code by your framework: Run refuses to store a secret under those names.

## From other products

Connecting [Sypnia Data](https://data.sypnia.com), [Files](https://files.sypnia.com) or [Mail](https://mail.sypnia.com) to an app adds their variables (`SYPNIA_DATA_URL`, the publishable key as plain, the secret key as a secret) to the environments you choose.

## Deploy tokens

A deploy token lets CI deploy one app to chosen environments, and nothing else: `run tokens create --app laespiga --env preview,production`. It is shown once, stored hashed, and revoked with `run tokens revoke`. For GitHub Actions, Run can trust the workflow's OIDC token instead, so no secret is stored in GitHub.
