Secrets
Workers often need credentials, for example a token for an external API. Managed deployments read them from the workspace Secrets Manager: you bind a workspace secret to an environment variable, and the worker reads the value from its environment at boot. Only secrets from the deployment's workspace can be bound.
Bind a workspace secret to your deployment:
# /// script
# dependencies = [
# "mistralai>=3.0",
# ]
# ///
import os
from mistralai.client import Mistral
client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
deployment = client.workflows.deployments.update_deployment(
name="<your-deployment-name>",
spec={
"backend_spec": {
"secrets": [
{
"env_var_name": "GITHUB_TOKEN",
"reference": "secret:workspace:github_token",
}
],
}
},
)
print(deployment.name)Changing a secret's value does not restart the worker. The worker keeps the value it read at boot. To pick up a new value, restart the deployment.
Available at build and at runtime
A binding reaches the worker twice:
- At runtime, as an environment variable, read when the worker boots.
- At build time, as a Docker build secret with the same name. Mount it in a
RUNstep, for example to install packages from a private registry:
RUN --mount=type=secret,id=UV_INDEX_USERNAME,env=UV_INDEX_USERNAME \
--mount=type=secret,id=UV_INDEX_PASSWORD,env=UV_INDEX_PASSWORD \
uv sync --frozen --no-devThe secret is available to that RUN step only and never persists in the image's history or layers. For compatibility, the value is also passed as a build arg with the same name, so existing Dockerfiles keep building. But a matching ARG writes the value into the image's history, and the build log warns about it: drop the ARG and read the secret with the mount instead.