What are environment variables?
Environment variables are dynamic values that exist in your Pod’s operating system environment. They act as a bridge between your Pod’s configuration and your running applications, allowing you to:- Store configuration settings that can change between deployments.
- Pass sensitive information like API keys securely.
- Access Pod metadata and system information.
- Configure application behavior without modifying code.
- Reference Runpod secrets in your containers.
Why use environment variables in Pods?
Environment variables offer several key benefits for containerized applications: Configuration flexibility: Environment variables allow you to easily change application settings without modifying your code or rebuilding your container image. For example, you can set different model names, API endpoints, or processing parameters for different deployments:Setting environment variables
You can configure up to 50 environment variables per Pod through the Runpod interface when creating or editing a Pod or Pod template.During Pod creation
- When creating a new Pod, click Edit Template and expand the Environment Variables section.
- Click Add Environment Variable.
- Enter the Key (variable name) and Value.
- Repeat for additional variables.
In Pod templates
- Navigate to My Templates in the console.
- Create a new template or edit an existing one.
- Add environment variables in the Environment Variables section.
- Save the template for reuse across multiple Pods.
Using secrets
For sensitive data, you can reference Runpod secrets in environment variables using theRUNPOD_SECRET_
prefix. For example:
Updating environment variables
To update environment variables in your Pod:- Navigate to the Pods section of the console.
- Click the three dots to the right of the Pod you want to update and select Edit Pod.
- Click the Environment Variables section to expand it.
- Add or update the environment variables.
- Click Save to save your changes.
When you update environment variables your Pod will restart, clearing all data outside of your volume mount path (
/workspace
by default).Accessing environment variables
Once set, environment variables are available to your application through standard operating system mechanisms.Verify variables in your Pod
You can check if environment variables are properly set by running commands in your Pod’s terminal:Accessing variables in your applications
Different programming languages provide various ways to access environment variables: Python:Runpod-provided environment variables
Runpod automatically sets several environment variables that provide information about your Pod’s environment and resources:Variable | Description |
---|---|
RUNPOD_POD_ID | The unique identifier assigned to your Pod. |
RUNPOD_DC_ID | The identifier of the data center where your Pod is located. |
RUNPOD_POD_HOSTNAME | The hostname of the server where your Pod is running. |
RUNPOD_GPU_COUNT | The total number of GPUs available to your Pod. |
RUNPOD_CPU_COUNT | The total number of CPUs available to your Pod. |
RUNPOD_PUBLIC_IP | The publicly accessible IP address for your Pod, if available. |
RUNPOD_TCP_PORT_22 | The public port mapped to SSH (port 22) for your Pod. |
RUNPOD_ALLOW_IP | A comma-separated list of IP addresses or ranges allowed to access your Pod. |
RUNPOD_VOLUME_ID | The ID of the network volume attached to your Pod. |
RUNPOD_API_KEY | The API key for making Runpod API calls scoped specifically to this Pod. |
PUBLIC_KEY | The SSH public keys authorized to access your Pod over SSH. |
CUDA_VERSION | The version of CUDA installed in your Pod environment. |
PYTORCH_VERSION | The version of PyTorch installed in your Pod environment. |
PWD | The current working directory inside your Pod. |
Common use cases
Environment variables are particularly useful for: Model configuration: Configure which AI models to load without rebuilding your container:Best practices
Follow these guidelines when working with environment variables: Security considerations:- Never hardcode secrets: Use Runpod secrets for sensitive data.
- Use descriptive names: Choose clear, descriptive variable names like
DATABASE_PASSWORD
instead ofDB_PASS
.
- Provide defaults: Use default values for non-critical configuration options.
- Document your variables: Maintain clear documentation of what each environment variable does.
- Group related variables: Use consistent prefixes for related configuration (for example,
DB_HOST
,DB_PORT
,DB_NAME
).
- Validate required variables. Check that critical environment variables are set before your application starts. If the variable is missing, your application should throw an error or return a clear message indicating which variable is not set. This helps prevent unexpected failures and makes debugging easier.
- Type conversion: Convert string environment variables to appropriate types (such as integers or booleans) in your application.
- Configuration validation: Validate environment variable values to catch configuration errors early.