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

> ## Agent Instructions
> These are the docs for Sevalla, a platform for deploying applications, databases, static sites, object storage and load balancers. The dashboard is at https://app.sevalla.com.
> Bold text in steps is an exact dashboard label.
> To act on a Sevalla account, prefer the Sevalla MCP server (https://mcp.sevalla.com/mcp, see https://docs.sevalla.com/ai-agents/overview.md), then the Sevalla CLI (https://docs.sevalla.com/developer-tools/cli.md), then the REST API (https://api-docs.sevalla.com, OpenAPI spec at https://api.sevalla.com/v3/openapi.json).
> Every page index is at https://docs.sevalla.com/llms.txt.

# Environment variables

> Add, import, update, export and delete an application's environment variables, choose build or runtime availability, use company-wide global variables, and see the variables Sevalla sets.

Environment variables pass configuration and secrets to an application without putting them in its code: database credentials, API keys, feature flags. Each variable is a key and a value, available during the build, at runtime, or both. An application gets its own variables, the company's global variables, and a few that Sevalla sets.

## How environment variables work

* **Availability.** Each variable is **Available during runtime**, **Available during buildtime**, or both (the default). Runtime variables reach every process of the application: the web process, background workers, cron jobs and jobs. You can't limit a variable to one process.
* **Next deployment.** Adding, updating or deleting a variable takes effect with the next [deployment](https://docs.sevalla.com/applications/deployments.md). Runtime-only changes need a restart, not a new build.
* **Storage.** Sevalla encrypts values at rest. The dashboard masks them; click the eye icon to show one.
* **Docker image applications** have no build step, so their variables are runtime only and the availability options don't appear.
* **Global variables.** The company's [global variables](#global-variables) also reach the application. A variable the application defines with the same key replaces the global one.
* **`.env` files.** Sevalla doesn't read a `.env` file from your repository. Import its contents into the dashboard instead.

> [!NOTE]
>
> You need permission to update the application to add, update or delete its variables.

## Add environment variables

**1. Open the Environment variables tab**

In the sidebar, click **Applications**, then click the application. Click the **Environment variables** tab.

**2. Enter the variables**

Click **Add environment variables**. Type a key and a value, and click **Add another** for more. To add many at once, paste the contents of a `.env` file into a key field, or click **Import .env** and pick the file.

**3. Choose the availability**

Under **Availability**, keep **Available during runtime** and **Available during buildtime** both selected, or clear the one you don't need. At least one must stay selected.

**4. Save and deploy**

Click **Add environment variables**, then deploy the application.

![The Add environment variables sheet with the Availability checkboxes and rows of keys and values](https://assets.sevalla.com/screenshots/light/app-environment-variables-add.png)

Keys must be unique on the application: a key that already exists shows `This key already exists`, and a key that appears twice in the form shows `Duplicate key`. Keys are trimmed; values are saved exactly as you type them.

When you paste or import a `.env` file, Sevalla reads one `KEY=value` per line. It skips blank lines and comments (`#`), removes a leading `export `, removes quotes around a value, keeps multi-line values in double or single quotes, and drops `# comments` after unquoted values. A key that's already in the form gets the pasted value.

The table lists each variable with its availability (**Build & Runtime**, **Buildtime** or **Runtime**) and who added or last updated it. Use **Filter by key…** to find one.

## Update or delete a variable

To update a variable, click **⋯** on its row, then **Update**. Change the key, the value or the availability, click **Update environment variable**, and deploy.

To delete one, click **⋯** on its row, then **Delete**, and confirm with **Delete variable**. To delete more than one, select their rows and click **Delete** with the count, for example **Delete 3 variables**. A deleted variable is gone from the next deployment on. You can't undo this.

## Copy or export variables

* **Copy all** copies every variable of the application to the clipboard, as `KEY=value` lines sorted by key.
* **Export** downloads the same content as a file named `export.env`.

Both include every variable, not only the filtered or selected ones, and neither includes the global variables.

## Use variables in your code

Read a variable the way your language reads any environment variable. For a variable named `API_KEY`:

| Language | Code |
| - | - |
| Node.js | `process.env.API_KEY` |
| Python | `os.environ.get("API_KEY")` |
| PHP | `getenv("API_KEY")` |
| Ruby | `ENV["API_KEY"]` |
| Go | `os.Getenv("API_KEY")` |
| Java, Scala | `System.getenv("API_KEY")` |

### Use variables during the build

Build-time variables are set in the build environment for Nixpacks, Railpack and Buildpacks, and passed to [Ingot](https://docs.sevalla.com/applications/builds/ingot.md#environment-variables-during-the-build) builds as a BuildKit secret. A [Dockerfile](https://docs.sevalla.com/applications/builds/dockerfile.md) build receives them as build arguments, so declare each one with `ARG` before you use it:

```dockerfile Dockerfile theme={"theme":{"light":"github-dark-default","dark":"github-dark-default"}}
ARG DATABASE_URL
RUN npm run build
```

See [Environment variables during the build](https://docs.sevalla.com/applications/builds/overview.md#environment-variables-during-the-build) for each build strategy.

### Reference another variable

A value can include another variable as `${KEY}`. Sevalla replaces the reference with that variable's value when it deploys, for example `DATABASE_URL` set to `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}`. References resolve against the application's and the company's variables with the same availability, up to 10 levels deep. At runtime, a reference to a key that doesn't exist stays as typed.

## Special characters

At runtime, Sevalla passes values literally: commas, quotes, backslashes and `$` reach your application unchanged, so don't escape them. Base64 values need no wrapping either. Avoid the `$(NAME)` pattern in a value: the container runtime can replace it with the value of the variable `NAME`.

During the build, values pass through the build shell. A `$` followed by a name, such as `$HOME` or `${UNKNOWN}`, is expanded there, so a build-time value containing `$` can change. If a secret contains `$`, make it available during runtime only.

Use letters, digits and underscores (`_`) in keys.

## Variables Sevalla sets

Sevalla adds these variables to every deployment, during the build, at runtime or both. You don't see them on the **Environment variables** tab. How each build strategy receives build-time variables is in [Environment variables during the build](https://docs.sevalla.com/applications/builds/overview.md#environment-variables-during-the-build).

| Variable | Value | Build | Runtime |
| - | - | - | - |
| `PORT` | The port the process should listen on: the [web process port](https://docs.sevalla.com/applications/networking.md#web-process-port) for the web process (`8080` unless you change it); `8080` for other processes, or the value of a `PORT` variable you add | No | Yes |
| `SVL_COMPANY_ID` | The company's ID | Yes | Yes |
| `SVL_APP_ID` | The application's ID | Yes | Yes |
| `SVL_APP_NAME` | The application's unique name, for example `storefront-x7k2m` | Yes | Yes |
| `SVL_PROCESS_ID` | The ID of the process this instance runs | No | Yes |
| `SVL_PROCESS_TYPE` | `web`, `worker`, `cron` or `job` | No | Yes |
| `SVL_DEPLOYMENT_ID` | The deployment's ID | Yes | Yes |
| `SVL_DEPLOYMENT_TRIGGER` | How the deployment started: `MANUAL_DEPLOY`, `AUTO_DEPLOY`, `DEPLOY_HOOK`, `PROMOTE` or `ROLLBACK_DEPLOYMENT` | Yes | Yes |
| `SVL_DEPLOYMENT_INITIATED_BY` | The ID of the user or API key that started the deployment, when there is one | Yes | Yes |
| `SVL_DEPLOYMENT_COMMIT_SHA` | The deployed commit (Git sources) | Yes | Yes |
| `SVL_DEPLOYMENT_BRANCH` | The deployed branch (Git sources) | Yes | Yes |
| `SVL_DEPLOYMENT_DOCKER_IMAGE` | The image the deployment runs | Yes | Yes |

A variable is left out when it has no value, for example the commit and branch of a Docker image deployment. For the web process, set the port on the [Networking](https://docs.sevalla.com/applications/networking.md#web-process-port) tab rather than with a `PORT` variable: Sevalla sets `PORT` to the web process port.

Sevalla doesn't set `NODE_ENV`. Add `NODE_ENV=production` yourself if your Node.js application expects it.

## Variables from internal connections

When you add an [internal connection](https://docs.sevalla.com/applications/networking.md#internal-connections) to a database or another application, you can turn on **Add environment variables to the application** to save the service's details as regular variables. You can rename them before you save, for example to the names your framework expects:

| Connected service | Variables |
| - | - |
| PostgreSQL, MySQL or MariaDB database | `DB_HOST`, `DB_PORT`, `DB_DATABASE`, `DB_USERNAME`, `DB_PASSWORD`, `DB_URL` |
| Redis or Valkey database | `REDIS_HOST`, `REDIS_PORT`, `REDIS_PASSWORD`, `REDIS_URL` |
| Application | `APP_HOST` (its web process's internal hostname) |

They're available during the build and at runtime unless you change it, and they apply at the next deployment. Deleting the connection doesn't delete them.

## Global variables

Global variables belong to the company and reach every application in it, from each application's next deployment. Use them for values many applications share, such as an error-tracking key. They work like application variables: each has a key, a value and an availability. They apply to applications only, not to static sites.

An application's **Environment variables** tab says how many global variables also apply to it, with a link to them. If the application defines a variable with the same key, the application's value wins.

![An application's environment variables, under a notice that 3 global environment variables also apply to it](https://assets.sevalla.com/screenshots/light/app-environment-variables-global.png)

> [!NOTE]
>
> Seeing global variables needs permission to view the company's applications, and changing them needs permission to update them, because a change reaches every application.

**1. Open Global variables**

In the sidebar, under **Tools**, click **Global variables**.

**2. Add the variables**

Click **Add environment variables**, enter the keys and values (paste or **Import .env** works here too), and choose the **Availability**.

**3. Save and deploy**

Click **Add environment variables**. Each application picks them up at its next deployment.

To update a global variable, click **⋯** on its row, then **Update**, and click **Update global environment variable**. **Copy all**, **Export** and deleting work as they do for an application.

## API and CLI

| Task | API | CLI |
| - | - | - |
| List an application's variables | [List environment variables](https://api-docs.sevalla.com/v3/applications/list-environment-variables) | `sevalla apps env-vars list --app-id <app-id>` |
| Add a variable | [Create environment variable](https://api-docs.sevalla.com/v3/applications/create-environment-variable) | `sevalla apps env-vars create <app-id> --key API_KEY --value <value>` |
| Update a variable | [Update environment variable](https://api-docs.sevalla.com/v3/applications/update-environment-variable) | `sevalla apps env-vars update <env-var-id> --app-id <app-id> --value <value>` |
| Delete a variable | [Delete environment variable](https://api-docs.sevalla.com/v3/applications/delete-environment-variable) | `sevalla apps env-vars delete <app-id> <env-var-id> --confirm` |
| List global variables | [List global environment variables](https://api-docs.sevalla.com/v3/global-environment-variables/list-global-environment-variables) | `sevalla global-env-vars list` |
| Add a global variable | [Create global environment variable](https://api-docs.sevalla.com/v3/global-environment-variables/create-global-environment-variable) | `sevalla global-env-vars create --key SENTRY_DSN --value <value>` |
| Update a global variable | [Update global environment variable](https://api-docs.sevalla.com/v3/global-environment-variables/update-global-environment-variable) | `sevalla global-env-vars update <env-var-id> --value <value>` |
| Delete a global variable | [Delete global environment variable](https://api-docs.sevalla.com/v3/global-environment-variables/delete-global-environment-variable) | `sevalla global-env-vars delete <env-var-id> --confirm` |

The API returns values decrypted, accepts keys of 1 to 255 characters and values up to 32,768 characters, and makes new variables available during both build and runtime unless you send `is_runtime` or `is_buildtime` as `false`.


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