# Variables

A variable is a name and a value your service reads from its environment, such as an API key. Each service has its own variables. Grayspar encrypts each value when it saves the value, and neither the CLI nor the dashboard shows a saved value again.

## Set a variable

To set a variable, run `grayspar env set` with the variable written as `KEY=VALUE`. Grayspar saves the value and redeploys the service, and the command waits until the service is live again:

```sh
grayspar env set STRIPE_KEY=sk_test_123
```

```text frame="terminal"
✓ Set variable STRIPE_KEY on app
✓ Redeployed <project-name>
```

When a project has several services, name the service with `--service`:

```sh
grayspar env set STRIPE_KEY=sk_test_123 --service api
```

## See your variables

To list the variables of a project, run `grayspar env`. The list shows names and dates and never shows values:

```text frame="terminal"
SERVICE    NAME          UPDATED
app        STRIPE_KEY    2026-11-07
```

## Remove a variable

To remove a variable, run `grayspar env remove` with its name. The service redeploys without it:

```sh
grayspar env remove STRIPE_KEY
```

## Send your .env files

A deploy reads `.env`, `.env.production` and `.env.local`, in that order, so a value in a later file wins. In a monorepo, the CLI reads the project's root folder and then the service's own folder, and a value beside the service wins. The files themselves are never uploaded. Only the variables you agree to send leave your computer.

When a deploy finds variables that are new to the project, the CLI lists their names and asks before sending them:

```text frame="terminal"
Found 2 new variables

SERVICE    VARIABLE        FILE
app        STRIPE_KEY      .env
app        SESSION_SECRET  .env

Send 2 variables to <project-name>? (Y/n)
```

A value that points at `localhost` or `127.0.0.1` stays on your computer, because it only works there. The CLI names each one, with the command that sets its production value.

When a value in a file differs from the saved value, the CLI asks which one wins. To answer ahead of time, pass `--env-conflict saved` or `--env-conflict file`.

To read no file, deploy with `--no-env`. To read one more file, name it with `--env-file`:

```sh
grayspar deploy --no-env
grayspar deploy --env-file .env.staging
```

## Variables during a build

A service built with Railpack can read every variable during its build, so changing any variable builds the service again. A service with a Dockerfile reads only the variables its Dockerfile declares as build arguments or secrets, and builds again only when one of those changes.

A framework can copy some variables into the code it sends to the browser. Next.js does this with every variable whose name starts with `NEXT_PUBLIC_`, so keep secrets out of those names.

## Names Grayspar reserves

Grayspar sets `GRAYSPAR_VOLUME_PATH` itself and refuses that name as a variable. Grayspar also refuses names that start with `RAILPACK_`. To choose a language version, use your project's own files, such as `engines` in `package.json` or a `.python-version` file.