Environment variables
The Modal runtime sets several environment variables during initialization. The keys for these environment variables are reserved and cannot be overridden by your Function or Sandbox configuration.
These variables provide information about the containers’s runtime environment.
Container runtime environment variables
The following variables are present in every Modal container:
MODAL_CLOUD_PROVIDER
— Modal executes containers across a number of cloud providers (AWS, GCP, OCI). This variable specifies which cloud provider the Modal container is running within.MODAL_IMAGE_ID
— The ID of themodal.Image
used by the Modal container.MODAL_REGION
— This will correspond to a geographic area identifier from the cloud provider associated with the Modal container (see above). For AWS, the identifier is a “region”. For GCP it is a “zone”, and for OCI it is an “availability domain”. Example values areus-east-1
(AWS),us-central1
(GCP),us-ashburn-1
(OCI).MODAL_TASK_ID
— The ID of the container running the Modal Function or Sandbox.
Function runtime environment variables
The following variables are present in containers running Modal Functions:
MODAL_ENVIRONMENT
— The name of the Modal Environment the container is running within.MODAL_IS_REMOTE
- Set to ‘1’ to indicate that Modal Function code is running in a remote container.MODAL_IDENTITY_TOKEN
— An OIDC token encoding the identity of the Modal Function.
Sandbox environment variables
The following variables are present within modal.Sandbox
instances.
MODAL_SANDBOX_ID
— The ID of the Sandbox.
Container image environment variables
The container image layers used by a modal.Image
may set
environment variables. These variables will be present within your container’s runtime
environment. For example, the debian_slim
image sets the GPG_KEY
variable.
To override image variables or set new ones, use the .env
method provided by modal.Image
.