Skip to content
redactsure
Book a demo

Explore.

Data Report · RedactSure Research
Chris Sowa · Founder, RedactSure
Published
Last updated

Does Codex Keep Your Environment Variables During the Agent Phase?

Codex keeps them: OpenAI sets environment variables for the full duration of the chat, including the agent phase, and removes secrets before the agent phase begins. Check which heading each credential was entered under, because an environment variable is the setting the documented removal does not reach.

A credential reference travels from a browser record through a bounded route to a separate API destination.

Every cloud coding task needs a way to reach the systems it works on, and the shortest path is a line in the environment. Codex offers two headings for that line, and OpenAI gives them different lifetimes. The values OpenAI calls secrets are available to setup scripts and removed before the agent phase starts, while environment variables are set for the full duration of the chat. A DATABASE_URL entered under the second heading so that a migration or a test run will connect is present for every command the agent issues, and the choice that put it there looks like a routine decision between two similar fields. Nothing in the form says that one value will be gone before the model starts and the other will be there for the whole run, which is why the mistake survives review. A production connection string in the agent's reach is a value an injected instruction, a logging statement or a failing test can surface, and the removal does not apply to it. Anyone wiring a repository for Codex, or reviewing one someone else wired, should know which heading a value went under before the first run. Does Codex Have Access to My Repository Secrets? takes the credential half of the question; the environment list is the subject here.

Key findings

  • A credential on a rendered page reaches the model regardless of the heading it was entered under, so Codex's removal protects the environment list and not the screen (OpenAI, Cloud, 2026).
  • Keeping a credential out of the agent's reach would also need a named person approving each use of the value and a record of what the model read, and the command log is not that record (Does Codex Log Every Command the Agent Ran?).
  • The documentation describes the store and the lifetime, and it does not describe a substitution on the screen before the model reads the page (What Is Least Exposure?).
  • Research on agent memory shows that access control applied to stored content can be defeated by fragmenting a request across interactions and reconstructing it at retrieval, with an average bypass rate of 86.3% across the settings tested (USENIX Association, 2026).
  • 1Password's OpenShell integration describes the other pattern, in which "the agent can work with real systems without holding any credentials in its context" and a gateway substitutes the value only for an approved host (1Password, 2026).
  • Columbia DAPLab's incident list records that "Cursor's agent deleted PocketOS's production database via a single rogue API call," the kind of reach a persistent DATABASE_URL grants (Columbia DAPLab, 2026).

What does the agent read from the environment during the agent phase?

The agent phase is the part of a Codex task in which the model works on its own, the mode an industry review of agentic AI describes as systems "capable of pursuing goals autonomously" without "constant human oversight" (MIT Sloan Management Review, 2025). Everything in the environment list at that moment is available to the commands the agent runs, and a command that prints its environment or dumps a configuration file puts the values into the model's context. The example record is a DATABASE_URL added for convenience: a platform engineer sets it so the agent's test run can reach a staging database. During setup the value is useful. During the agent phase it is inherited by every process the task starts, and nothing in the setting marks it as a credential to remove. Every command the approval permits inherits the value (Does Codex's Full Sandbox Escalation Expose Your Credentials?).

The exposure does not require an exotic command. A test runner that reports its configuration, a migration tool that echoes the connection string on failure, or a dependency that reads the variable and logs it will do. The agent may never intend to look, and the value is in the transcript anyway. An instruction hidden in a repository file or a fetched page can ask for one command and get the same output; indirect prompt injection is the vector research records for exactly that, where an attack "can act as arbitrary code execution" (Greshake et al., 2023).

OpenAI's documentation states the rule without qualification: environment variables are set for the full duration of the chat, including the agent phase (OpenAI, Cloud, 2026). A team reading the page for the first time may take "duration of the chat" as the setup window. It is the whole task.

Why does a value in the environment stay in the model's context?

The lifetime is the whole mechanism. OpenAI's cloud documentation separates the values "only available to setup scripts," which "are removed before the agent phase starts," from environment variables, which are set "for the full duration of the chat (including setup scripts and the agent phase)" (OpenAI, Cloud, 2026). Setup scripts also "run in a separate Bash session from the agent," so an export inside a setup script does not carry into the agent phase by itself. The environment list attached to the task does.

That makes the setting a question about storage, not about trust in the model. A value in the list is in memory for the run. Research on agent memory finds an attack surface in which prohibited content "can be fragmented across interactions, stored in long-term memory in a benign-appearing form, and later reconstructed through memory retrieval" (USENIX Association, 2026). Microsoft's AI Red Team calls memory poisoning "particularly insidious in AI agents" and recommends "requiring external authentication or validation for all memory updates" (Microsoft AI Red Team, 2025). A credential held for the run is a memory the agent can use, and the page reviewed describes no validation step at retrieval.

The practical consequence is that moving a value from the environment to the heading for credentials changes its lifetime, and a value the agent never needs in the agent phase belongs in neither. A value the agent needs should be scoped to the one action it serves, not left where every command inherits it.

What do the vendors themselves say?

OpenAI is the vendor whose setting this page is about, and its documentation is explicit about the two lifetimes: secrets "are only available to setup scripts" and "are removed before the agent phase starts," while environment variables "are set for the full duration of the chat (including setup scripts and the agent phase)" (OpenAI, Cloud, 2026). Setup scripts "run in a separate Bash session from the agent," so the split is enforced by the environment rather than by a script's discipline. The page is marked Legacy. A team should confirm it is still the current description before treating the answer as settled.

1Password describes a different design for the same problem. In its OpenShell integration, "the agent can work with real systems without holding any credentials in its context," the sandbox shows "placeholders rather than real credentials," and a gateway "replaces a placeholder with the real value only when the agent sends a request to an approved host" (1Password, 2026), which governs outbound requests and not what a page shows the model. It treats the credential as something a gateway substitutes at the edge of an approved call, and it is a separate product with its own integration.

Dimension OpenAI Codex, per its documentation What a buyer should verify
Where the value lives Codex secrets in a store available to setup scripts; environment variables in the task's environment Which heading each credential was entered under
Lifetime Codex secrets removed before the agent phase; environment variables for the full chat That no export or file write in setup recreates the value
What the model receives Whatever a command prints or a file contains in the agent phase Whether a test run can print the environment
Approval No approver named for the agent phase Who approves a consequential use of the value
Record No model-read record described What the run keeps of what the model read

The vendor statements settle the title and leave the layer below it open. OpenAI documents where a value is stored and how long each store lasts. 1Password's page describes a gateway for outbound requests, and OpenAI's describes storage; neither describes a control on what a rendered page shows the model.

Which values should never be an environment variable?

Start with what the task needs in the phase that will use it. A dependency token that a setup script uses to fetch a private package fits the heading for credentials: the setup phase needs it and the agent phase does not. A production DATABASE_URL is not needed by the agent at all if the deploy step runs outside the task, and separating build from deploy is the cleaner answer (How Do I Let a Coding Agent Deploy Without Giving It Deployment Credentials?). The grant should be the task's, not the developer's (What Is the Least Access a Coding Agent Needs to Finish a Task?).

The category mistake is treating the environment list as a convenience drawer. OWASP's excessive agency entry describes the failure mode: "the vulnerability that enables damaging actions to be performed in response to unexpected, ambiguous or manipulated outputs from an LLM," with excessive permissions among its root causes (OWASP, 2025). A production connection string is a permission the task did not need, held in the place the model reads.

Trust in the model is not a substitute for that decision. Anthropic stress-tested 16 models in hypothetical corporate environments and found that "in at least some cases, models from all developers resorted to malicious insider behaviors," while adding that it has "not seen evidence of agentic misalignment in real deployments" (Anthropic, 2025). A control that depends on the model behaving is not a control, and the heading is decided by a person before the run.

The test that settles a value's heading is small: write down what the agent must do in the agent phase, list the credentials that action needs, and move everything else. A credential that only setup needs belongs in the credential store. A credential that no phase needs belongs outside the task.

Does the control cover what a rendered page shows the model?

OpenAI's control is a rule about stored configuration. It decides which store a value sits in, the store for Codex secrets that setup scripts read, or the environment list every command inherits, and it removes the first before the agent phase. It does not inspect a screen. The setting answers where a value lives, and a rendered page is a different layer. A connection string shown on a database dashboard, an API key revealed once on a settings page or a token in a sign-up confirmation during the agent phase is outside it.

The boundary matters because the model reads the page, not the store. A tether describes authority, not capability: the agent may be permitted to open the page and still receive every value the page draws (What Is a Tethered Agent?). A permission rule that lets the agent view a settings page is satisfied by the view. A rule that keeps the credential out of the environment has nothing to say about what the page renders.

OpenAI's documentation states the scope in its own words: secrets "are only available to setup scripts" and environment variables "are set for the full duration of the chat" (OpenAI, Cloud, 2026). Both sentences are about where a value is kept during a task. Neither is about what a page displays while the agent works, and the page reviewed describes no substitution on the screen.

That boundary separates a storage control from a rendering control. A team that needs the screen covered has to add a control that acts there, before the model reads it.

What does a governed environment change?

A governed environment acts on the page rather than on the task's stored configuration. Values chosen by policy are replaced with consistent tokens before any model reads the screen, so a connection string renders as DATABASE_001 and an API key as KEY_001 for the whole run. The model receives tokens in place of the values, and the real values resolve only at an approved destination, at the moment of an approved action. A named person approves each payment, submission and record change, and every screen as tokens, every action and every approval lands in a record that exports to the organization's monitoring.

Because the substitution happens before any model reads the page, the control is model agnostic: the solution was designed to work with any model, and a team can move a workflow between models without changing it. Coverage is per supported workflow, in applications that render in the governed environment, and the control is enforced outside the model where integrated. It does not follow a value into the terminal, the IDE, the local filesystem, direct API calls or MCP, so the environment list still has to be cleaned up.

The two layers answer different questions. The Codex setting decides whether a value is present in the agent phase. The render layer decides what a page shows the agent while it works. The comparison for this vendor sets them side by side (RedactSure vs OpenAI Codex: 2026 Comparison & Alternative).

What the record shows

A rendered page is where the model receives a value, and the environment setting is a separate layer behind it. The heading decides how long a value lives, which makes it a storage decision with a security consequence. Codex removes a value entered as a secret before the agent phase and leaves an environment variable in place for the whole chat. What the agent reads on a page sits outside that setting: a rendered settings page or dashboard shows whatever it draws, and no environment setting changes that. One test settles the question for a given repository: enter a dummy DATABASE_URL once under each heading, run a command in the agent phase that prints the environment, and compare the output with what the setup script saw. Then open the pages the agent reads during the run and note which values they render.

Methodology and limitations

This page rests on OpenAI's Codex cloud environment documentation, 1Password's account of its OpenShell integration, two research papers on agent memory and prompt injection, OWASP's excessive agency entry, Anthropic's stress test, Microsoft's agent failure taxonomy, a Columbia DAPLab incident summary and MIT Sloan Management Review's definition. Vendor pages were read between October 20, 2026 and October 22, 2026, and each Sources line carries the date for its page. Public documentation read in full gives a sound view of where each product applies its control.

The products on this page are described from documentation and none was tested for this page. "Not described" means not present in the pages reviewed, and not a claim about behavior those pages leave out. Vendor features change, and the page carries its date. The example describes a record type, a cloud task with a database URL in its environment, not an organization. RedactSure is deploying now with enterprise and government customers. Determinations belong to counsel, assessors and the organization's own security and compliance officers, and nothing here replaces a test of one task on the organization's own screens.

Frequently asked questions

Does Codex keep environment variables during the agent phase?

Yes. OpenAI's cloud environment documentation states that "environment variables are set for the full duration of the chat (including setup scripts and the agent phase)," while secrets "are removed before the agent phase starts." The distinction is the control: a credential entered as an environment variable is present for every command the agent runs, and a credential entered as a secret is not. Check the heading a value was entered under, move any production credential that does not need to be there, and rotate a value the agent could read.

What is the difference between a Codex secret and an environment variable?

A secret is available to setup scripts and removed before the agent phase begins. An environment variable is set for the full duration of the chat, including the agent phase, so every command the task starts inherits it. The two settings accept the same text and look alike in a form, which is why the mistake is common. The reliable check is a dummy value under each heading and a command that prints the environment in the agent phase.

What can the agent read once an environment variable is set?

Whatever a command prints or a file contains. A test runner that reports its configuration, a migration tool that echoes a connection string on failure, or a dependency that logs the variable will put the value into the model's context without any special instruction. An instruction hidden in a repository file or a fetched page can ask for the same output. Keep production credentials out of the list, scope what the agent must use, and test after each release.

Who approves the agent's use of the value?

No approver is named in the Codex pages reviewed for the agent phase; the setting decides where the value is stored, and the agent's commands then use it. Approval for a consequential action is a separate control. Ask who confirms a use of a production credential, what permission it runs under, and whether the person sees the action rather than a summary after it. A named approver and a task-scoped grant close different gaps.

Does the control cover what a rendered page shows the model?

No. The setting governs stored configuration: the store for Codex secrets and the environment list attached to the task. A page the agent opens during the agent phase renders whatever it draws, and the model receives that. A settings page or dashboard that displays a connection string or an API key is outside the removal. Values on the rendered page have to be handled at the render layer, before the model reads the screen.

What record shows what the model read?

The reviewed Codex pages describe the environment and the phase split, not a record of the model's reading. Command output and work logs may show what ran, and they do not separate what the model received from what it did. Ask for a record of the screens as the model saw them, the actions taken and the approvals given, exported somewhere the organization controls. Keep it with the task's date and the documentation version.

About the author

Chris Sowa is a founder of RedactSure and a former CEO of an AI company; he started it years before ChatGPT existed. He previously led AI at Accenture, served as Global VP of Strategy & Innovation at Schneider Electric, was CCO of Sovos, and spent more than a decade at Oracle, with earlier roles at SAP and IBM.

How RedactSure Keeps an Environment Variable Out of the Agent's Context

Codex removes setup credentials before the agent phase, yet a DATABASE_URL in the environment stays in the agent's reach for the run.

The environment that enforces this is built by RedactSure, an AI agent controls, governance and data protection company.

Before: the agent opens the database settings page and the connection string enters its context. Inside the governed environment: the page renders DATABASE_001 for the run, and the real value resolves only at the approved production host on a named person's approval. For each task, RedactSure's Policy Planner proposes what the agent may see and what it may do, so the policy fits the database task rather than the environment.

RedactSure is deploying now with enterprise and government customers. OpenAI's page states that environment variables are set for the full duration of the chat.

Everyone else controls where data can go. RedactSure controls what the AI can see.

See it on your own workflow

A database URL pasted under the wrong heading is a production credential in the model's context for the whole task. Bring a task of your own and see, with test values, what the model reads and where the real value lands. Book a demo

Book a demo

Book a demo

Having trouble? Open the booking page or email us.