Environment Variable
Last Updated: July 29, 2026 | By Mihail Sebastian | AI Dictionary
A named value the operating system passes to a program when it starts. Applications read API keys, paths, and settings from it instead of hardcoding them.
What is an Environment Variable?
An environment variable is a named value that the operating system passes to a program when it starts. Programs read configuration from it (API keys, file paths, feature flags) instead of hardcoding those values into source code.
The separation matters for two reasons. Secrets stay out of the codebase, and the same code runs unchanged in development, testing, and production because each environment supplies its own values.
How Environment Variables Work
Every process inherits a set of key-value pairs from whatever launched it. You set one in a shell (export HF_TOKEN=...), in a .env file, in a CI system’s settings, or in a container, and the program reads it by name at runtime.
ML tooling leans on this mechanism. CUDA_VISIBLE_DEVICES controls which GPUs a training job sees, and credentials for services like Hugging Face or OpenAI travel as variables such as HF_TOKEN and OPENAI_API_KEY.
Containers follow the same pattern. A Dockerfile sets defaults with its ENV instruction, and values passed when the container starts override them.
Example of an Environment Variable
A team trains a model on a shared GPU server and deploys it to the cloud. The training script needs a dataset path and two specific GPUs; the deployed service needs a database URL and an API key.
None of those values appear in the code. On the server, CUDA_VISIBLE_DEVICES=0,1 and DATA_DIR=/mnt/datasets are set before the job starts; in the cloud, the platform injects DATABASE_URL and the key from its secret store. One codebase, two environments, zero credentials in version control.
Related AI terms: Dockerfile · Deploy · CUDA · Version Control
Did you like the Environment Variable gist?
Learn about 250+ need-to-know artificial intelligence terms in the AI Dictionary.
Mihail Sebastian — Writes about AI governance, regulation, and the technology behind them. Placeholder bio — replace with a real credential line. About