# Env files

> Pass variables, secrets and files to a model's containers with versioned env files, attached per replica and pinned.

## What an env file is

An env file is a named file that a model's containers get when you deploy. Use one to hand the containers what they need, such as an access token for a model hub or an engine setting, without writing it into a deploy profile. Each env file has one of two usages, which you choose when you create it and cannot change later:

- **Variables**: `KEY=value` lines, the same format Docker Compose reads from a `.env` file. The containers read them into their environment.
- **Mounted file**: any text, for example a token, a certificate, or a YAML or JSON configuration file. Each container of the replica gets the file, read-only, at a container path you choose when you attach it.

Every env file is treated as a secret. The control plane stores it encrypted, never shows its content in a list, a log line or an error report, and shows it only when an administrator chooses **Reveal**. Each reveal is recorded in the audit log.

## Creating and changing one

Env files live under **Configuration → Env files**. Administrators can:

- **Create env file**: choose a filename, a usage and enter the content. The filename is the name of the file your containers see, extension included, for example `engine.env` or `hf-token.txt`. It may use letters, digits, `.`, `-` and `_`, up to 128 characters, and cannot be `.` or `..`.
- **Save new version**: every save is a new version with the next number, and a saved version never changes. "Start from version N" loads the newest version's text into the editor (this is a reveal, and is recorded). If someone else saved a version while you were editing, the save is refused; start again from the newest version.
- **Rename**: changes the name used by future deploys. Running replicas keep the filename they started with.
- **Delete** a version: removes its values for good, for example after a leaked secret. The version's number and SHA-256 remain, so every replica pinned to it shows it as removed.

In a variables env file, every line must set a value (`KEY=value`; `KEY=` sets an empty one). A line with only a name is refused, because the inference node has no environment of its own to take the value from. A refused save names the line number, never the line. The content of a mounted file is not checked: it is used as you saved it.

## Attaching env files when you deploy

On the deploy page, each new replica in the **Deploy** list has an **Env files** button. In its dialog, attach:

- **Variables**: variables env files, in the order they apply.
- **Mounted files**: a mounted file and the **Container path** where it appears, for example `/run/secrets/hf-token.txt`. The path starts with `/`, has no `.` or `..` part, and is at most 512 characters.

See [Deploying models](/en/platform/docs/v5.10/guides/models-and-deployments/deploying-models/index.md). API and MCP clients can also attach env files to the whole inference service.

For variables, the order is the only rule. A replica reads the service's env files first, then its own, each in the order they were attached; when two files set the same variable, the later file wins. A variable set in the deploy profile's own `environment` wins over every env file.

A deploy is refused, with the reason, when:

- a mounted file's container path is one the model already uses for its own files or model weights, or lies inside or around one of them: one would hide the other. Choose another path.
- two mounted files have the same container path, or two env files of one replica have the same filename.
- a mounted file is attached as variables, or a variables env file as a mounted file.
- the inference node's software is too old for a mounted file or a filename that is not `<name>.env`. Update the node's software under **Inference nodes**, in the node's menu under **Software update**, then deploy again.

A deploy pins the newest version of each attached env file. An env file whose newest version was deleted cannot be attached until you save a new version.

## Where the files are on the inference node

The inference node writes a replica's env files into a folder of the replica's own in its data directory. Only the inference node's own user account can open that folder. A variables env file in it can be read only by that account. A mounted file can be read by every user, because the process in a container can run as any user and must be able to read the file. The folder keeps every other user on the machine out. In the container, the mounted file is read-only. The inference node deletes the folder when the replica is removed.

## What each replica shows

Each replica lists the env file versions it is pinned to, with the filename, how it is used (variables, or mounted at its container path), version number and the start of the SHA-256:

- **behind**: a newer version has been saved since the replica started. The replica keeps running with the version it has; restart or redeploy it to pick up the newest version.
- **removed**: the pinned version was deleted. The replica cannot start again with it. Save a new version of the env file under **Configuration → Env files**, then restart the replica.

## When a replica fails because of an env file

| What the replica shows | What to do |
|---|---|
| The pinned env file version was deleted | Save a new version of that env file under **Configuration → Env files**, then restart the replica. |
| The inference node could not write the env files to its data directory | Free space or fix the permissions of the inference node's data directory; the node retries on its own. |
| An error report was generated for a mismatched env file | This is a defect, not a setting. Send the error report id to support; the report names the env file, its version and both SHA-256 values, never a value. |
