environment variable
An environment variable is a named setting that is not contained in the program's code but is provided to the program from outside, by the environment running it, at startup; the program reads from it how to operate.
In plain terms
Imagine that in an office, the Wi-Fi password, the printer name, and the on-duty person are written on a bulletin board. The new colleague does not ask anyone but just looks at the board. An environment variable is such a bulletin board note for programs: a name and its associated value, for example LANGUAGE=Hungarian.
It is useful for making the same program behave differently on different machines without anyone rewriting the code. On the developer's machine, it connects to the test database; on the live server, it connects to the real one, because what is on the 'bulletin board' differs.
You most often encounter it when you need to provide a secret key (API key) for an AI service. You do not write this into the program's text but place it in an environment variable, allowing the code to be shared without the key going with it.
Unlike a simple menu setting, it does not belong to a specific program but to the environment in which the program runs. Multiple programs can read the same value.
How it works
- Someone (you, the system administrator, or an installer) provides a name–value pair, for example API_KEY=abc123, in the command line or system settings. A common solution is also a file named .env: this is not managed by the operating system but is read at startup by the program or a helper tool.
- When a program starts, the operating system passes it a copy of the currently valid variables; this is the program's 'environment'.
- The program asks by name for what it needs and decides based on the value: which server to connect to, what language to write in, where to save.
- If the program itself launches another program, the new program by default inherits a copy of the environment. For example, commands run by a coding agent also see the same variables.
- The change does not propagate backwards: the running program sees the old value, so it usually needs to be restarted after modification. Additionally, a value specified in the command line typically exists only in that window and is lost when the window is closed.
An everyday example
You want to try an AI tool on your own computer, and the installation guide asks you to "set your API key as an environment variable". You enter a line in the command line or a .env file, and from then on the tool knows in whose name and on whose account it is working. You never had to type the key into the program.
Who is affected
A common misconception
Limits and risks
- The value is plain text, so truly sensitive secrets should be kept in a separate secret management system.
- The .env file is easily accidentally uploaded to a public code repository, where automated crawlers can find the keys within minutes.
- If you grant an agent access to your machine, it can also see your environment variables, so consider what keys are configured.
- A misspelled name or a missing variable often yields only a vague error message, making it hard to spot the issue.
Similar, but not the same
- configuration file – A configuration file is a settings list saved to disk for a specific program, whereas an environment variable lives in the runtime environment and can be read by multiple programs.
- API key – The API key itself is the secret identifier; the environment variable is just the 'drawer' where it is usually kept.
- variable (in programming) – A plain variable lives inside the program and disappears when the program stops, while an environment variable is supplied to the program from outside.
Related concepts
configuration, operating system, runtime environment
.env file, PATH variable
API key, command line, secret management, configuration file, container
A brief history
The current form of environment variables appeared in 1979 with the seventh release of the Unix operating system (Version 7 Unix). Since then, every major operating system has adopted it, from Windows to macOS to Linux.
Where things stand
As of late 2026, it is still one of the basic tools for configuring software, and the keys for AI tools and agents are typically provided this way. The emphasis is shifting toward security: more and more companies load the values from a secrets management system and restrict what an agent can see of them.
Also known as
environment variable · environment variables · environment variable · env var · environment variable · ENV · .env · system variable
Sources
This entry was machine-edited and has undergone machine expert review; the “In the news” section updates automatically from Agent Age stories.