Join our Newsletter — 33% off our NHI Course
Agentic AI & Autonomous Identity

Codex CLI

← Back to Glossary
By NHI Mgmt Group Updated November 26, 2026 Domain: Agentic AI & Autonomous Identity

Codex CLI is OpenAI's open-source coding agent that runs in a local terminal, reading and editing files and running commands in a chosen project directory. Because it acts on the user's machine, exposed credentials and prompt injection from repository content are the main risks. Defenders review its approval and sandbox settings and keep secrets out of reach.

What Codex CLI Is in Practice

Codex CLI is not just a coding helper, it is a local terminal agent that can read repository files, edit code, and execute commands inside the project directory. That makes it useful for real development work, but it also means its authority is tied to the machine and workspace it can reach, not just the prompt the user typed.

Because the agent operates inside a live development environment, its behaviour is shaped by the repository contents, the files it can inspect, and the level of command approval it is granted. In that sense, Codex CLI sits closer to an operational tool than a chat interface: the security boundary is the terminal session, the working tree, and the approvals behind it.

Why Terminal-Based Coding Agents Change the Security Model

Terminal coding agents are different from ordinary code assistants because they can turn instructions into file changes and shell actions. That makes them efficient, but it also makes them sensitive to prompt injection, unsafe command execution, and accidental overreach if the surrounding controls are loose. The main question is not whether the model is intelligent, but whether the agent has the right limits when it is allowed to act.

For a product like Codex CLI, the important security shift is that the agent can be influenced by content already present in the repository. Malicious or poisoned instructions in README files, scripts, comments, or other project assets can be interpreted as guidance unless the approval and sandbox model is strict enough to stop unsafe side effects.

In practice, that means the agent’s risk posture depends on the combination of local file access, shell reach, network reach, and how much manual approval is required before a command runs or a file changes. Those settings are the difference between a controlled assistant and a tool that can be steered into unwanted behaviour.

Credentials, Secrets, and Prompt Injection Exposure

Two issues dominate the security conversation around Codex CLI: exposed credentials on the user’s machine and prompt injection hidden in repository content. If the agent can see environment variables, local config files, token stores, or developer secrets, an injected instruction can try to exfiltrate or misuse them through ordinary-looking commands.

This is why secrets handling matters even when the agent is only used in a local project directory. The danger is not limited to the model “knowing” sensitive material, it is that the agent may be able to read, copy, or use secrets as part of its normal workflow if those values are within reach of the terminal session.

Defensive practice is therefore about reducing the agent’s available blast radius. Keep secrets out of the repository, avoid broad environment exposure, and treat any repository-provided instruction as untrusted until it has been validated against the task. That discipline matters even more when the agent can run commands without a human checking each step.

Sandboxing, Approval, and Trust Boundaries

Codex CLI’s approval and sandbox settings are not cosmetic options, they are the practical controls that determine whether an agent can safely operate in a developer workflow. A stricter sandbox limits how far a command can reach, while approval gates create a pause before the agent can modify files, contact external services, or execute risky actions.

The safest posture is to align the agent’s permissions with the minimum scope needed for the task. If a project only needs local edits, the agent should not be able to wander beyond that directory or reach unrelated credentials and services. If network or command breadth expands, the trust boundary expands with it.

That is why guidance around Codex CLI tends to focus on managed settings, approval discipline, and keeping the working environment clean of secrets. The goal is to preserve the productivity benefit of an agentic terminal workflow without letting the agent inherit more authority than the job requires.

Risk and Threat Considerations

Codex CLI’s main risks come from the combination of local execution authority and untrusted repository content. A poisoned prompt or malicious file can steer the agent toward unsafe commands, and any exposed credentials on the host can turn that mistake into real compromise.

Failure mechanism: The agent trusts content inside the workspace, then uses that content to decide what to read, edit, or execute. If the workspace contains injected instructions and the sandbox or approval model is weak, the agent can be pushed into command execution, secret exposure, or unintended outbound actions.

Impact: The result can be source-code tampering, credential leakage, misuse of developer access, or a broader compromise of the local development environment and connected services.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-02 — Secret LeakageCodex CLI can expose credentials and tokens on the local machine.
NHI-04 — Insecure AuthenticationThe agent's approval and access settings govern how it authenticates to tools and repos.
NHI-05 — Overprivileged NHICodex CLI can gain excessive terminal and file-system authority if sandboxing is loose.
Recommendation — Keep secrets out of the agent's reachable environment and rotate any exposed credentials. Constrain authentication paths and require stronger approvals before the agent can use sensitive access. Reduce the agent's permissions to the minimum needed for the task and workspace.
OWASP Agentic AI Top 10ASI02 — Tool MisuseThe agent can misuse shell tools when prompt injection steers its actions.
ASI03 — Identity & Privilege AbuseExposed host credentials can be abused through the agent's runtime authority.
ASI09 — Human-Agent Trust ExploitationPrompt injection leverages user trust in repository instructions and outputs.
Recommendation — Gate high-impact tool use and validate commands before they run. Limit the agent's privilege and prevent access to sensitive credentials in its runtime context. Treat workspace content as untrusted and verify agent-generated actions before approval.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementCredential exposure and token handling are central to the risk profile described.
AC-6 — Least PrivilegeThe key control question is how much local command and file access the agent receives.
SI-10 — Information Input ValidationPrompt injection is an untrusted-input problem in repository content.
Recommendation — Protect, rotate, and manage credentials so the agent cannot reuse exposed authenticators. Grant only the permissions required for the task and strip everything else. Validate repository-sourced instructions before they influence automated actions.

Practitioner Guidance

Why practitioners should care: Codex CLI is most useful when teams treat it like a controlled executor, not a passive assistant. The practical task is to decide what the agent may see, what it may change, and which actions always require human review.

What to watch for: The strongest warning signs are broad file visibility, permissive execution settings, and secret-bearing environments used in the same session as the agent. If those conditions exist together, the likelihood of prompt injection or accidental secret exposure rises sharply.

Practitioner takeaway: The safest deployment pattern is to narrow the workspace, restrict approvals, and keep sensitive material outside the agent’s reach unless the task genuinely requires it.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on November 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org