# Variables and secrets (/docs/projects/variables-and-secrets.md)



A project can carry **variables** (plain settings such as a region or a batch size) and **secrets**
(API keys, tokens and passwords). Your code reads both the same way:

```python
import os

token = os.environ["HF_TOKEN"]
```

## Adding one [#adding-one]

Open **Variables & secrets** in the Studio's left column, under Data connections, and choose
**+ Variable** or **+ Secret**. Give it a name in capital letters, digits and underscores
(`HF_TOKEN`, `WANDB_API_KEY`), and a value.

|                    | Variable                                | Secret                                                           |
| ------------------ | --------------------------------------- | ---------------------------------------------------------------- |
| Shown after saving | Yes, to people who can edit the project | Never. It shows as dots                                          |
| Can be changed     | Edit the value                          | Replace the value, or remove it                                  |
| Maximum value      | 1,000 characters                        | 4 KB                                                             |
| Stored             | With the project                        | Encrypted in AWS Secrets Manager; ByteRun keeps only a reference |

People who can only view the project see the names, not the values.

## When a change takes effect [#when-a-change-takes-effect]

Variables and secrets are set when compute **starts**. A change you make while compute is running does
not reach the running kernel. The panel then says so and offers **Restart compute**, which saves your
notebook, stops the compute and starts it again with the same template and size. Restarting clears the
kernel's memory (variables and loaded data), so pick a good moment.

If no compute is running, nothing needs restarting: the next start picks the change up.

## How a secret reaches your code [#how-a-secret-reaches-your-code]

When you save a secret, ByteRun passes the value to AWS Secrets Manager and keeps only a reference. It
has no permission to read the value back. When compute starts, AWS hands the value to the project's
container as an environment variable, so it is not part of the request that starts the compute and does
not show in the compute's settings.

Anything your code prints is saved in the notebook's output. **Don't print a secret.** ByteRun does not
yet hide secret values in output.

## Names you can't use [#names-you-cant-use]

ByteRun sets some variables itself, and a project can't override them: `OPENAI_API_KEY`,
`OPENAI_BASE_URL`, `ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL`, `PATH`, `HOME`, and names starting with
`BYTERUN_`, `AWS_`, `ECS_`, `JUPYTER_` or `NB_`. The AI keys carry ByteRun's own short-lived credential for
the [AI assistant](/docs/ai-assistant.md), not a provider key.

A name can be a variable or a secret, not both. To turn a variable into a secret, remove the variable and
add the secret.

## Database passwords [#database-passwords]

For databases, use a [data connection](/docs/sql-and-data/data-connections.md) instead of a secret. Your code then
never holds the password at all.
