codex-security
CLI and TypeScript SDK that scans a codebase to find, validate and fix security vulnerabilities.
Overview
`npx @openai/codex-security scan .` walks a checkout and leaves JSON results on stdout, while `--mode deep` spreads discovery across workers and subagents until it stops turning up anything new. Across runs, `scans compare BEFORE_SCAN_ID AFTER_SCAN_ID` matches findings by root cause and labels them new, persisting, reopened, resolved or unknown, so a second scan reports movement instead of restating the whole report. It is a poor fit as a pre-commit gate: deep discovery runs until `--max-time-hours`, which defaults to 96. Access is also gated — the CLI needs access to Codex Security, and some cybersecurity requests and protected findings require Trusted Access for Cyber approval, so cloning the repo on its own scans nothing.
What can you do with codex-security?
- One command, or one SDK call —
npx @openai/codex-security scan .is the whole entry point;--modeland--effort hightune the run. The TypeScript equivalent isnew CodexSecurity()plusawait security.run("."), which returnsresult.reportPath. - Deep scans with an explicit stop condition —
--mode deeptakes--workersand--subagentsfor parallelism and--stop-after-no-new 3,--max-discovery-runs 10and--max-time-hours 1.5as budgets. Discovery otherwise halts at 96 hours, and findings completed before the limit are still returned. - Findings tracked across scans —
scans compare BEFORE_SCAN_ID AFTER_SCAN_IDreuses saved matches and matches the rest by root cause; findings stayunknownwhere coverage was incomplete or the original location was never reviewed.findings list [repository]surfaces open findings not confirmed by the latest scan. - Swap in another inference provider —
--provider openrouter,--provider fireworksand--provider amazon-bedrockpair with a matching--modelsuch asanthropic/claude-sonnet-4.5. Bedrock acceptsAWS_BEARER_TOKEN_BEDROCKas well as standard access keys, profiles, web identity and the default AWS credential chain. - Containerized bulk scanning — The official image and its Docker Compose config run noninteractive, resumable scans of repositories pinned to immutable Git revisions.
--knowledge-base PATHshares security documents with every repository,--scan-prompt-file PATHcarries the scan instructions common to all of them, and apromptCSV column holds the instructions for one repository.
Documentation
Reproduced from the openai/codex-security README, published under Apache-2.0. Read the original ↗
Codex Security
@openai/codex-security is a CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities in your code.
See the Codex Security documentation for more details.
Some cybersecurity requests and protected findings require approval through Trusted Access for Cyber. To apply or check your access, visit chatgpt.com/cyber.
Quick start
Requires Node.js 22.13.0 or later in the 22.x release line, Node.js 24.x, or Node.js 26.x; Python 3.10 or later; and access to Codex Security.
npm install @openai/codex-security
npx @openai/codex-security login
npx @openai/codex-security scan .
npx @openai/codex-security scan . --model gpt-5.6-terra --effort high
npx @openai/codex-security scan . --scan-prompt-file scan.md --post-scan-prompt-file follow-up.md
npx @openai/codex-security scan . --mode deep --workers 2 --subagents 0 --stop-after-no-new 3 --max-discovery-runs 10 --max-time-hours 1.5
For CI, set OPENAI_API_KEY or CODEX_API_KEY instead of signing in.
Environment API keys are passed directly to the current scan and are never
stored in Codex’s credential home or system keyring.
Deep-scan discovery stops after 96 hours by default. Set --max-time-hours to
any positive number of hours, including fractional hours, up to 96. Completed
findings are preserved and returned when the limit is reached.
To use another inference provider, set its API key and select a model:
export OPENROUTER_API_KEY="<your-openrouter-api-key>"
npx @openai/codex-security scan . --provider openrouter --model anthropic/claude-sonnet-4.5
export FIREWORKS_API_KEY="<your-fireworks-api-key>"
npx @openai/codex-security scan . --provider fireworks --model accounts/fireworks/models/qwen3-235b-a22b
export AWS_BEARER_TOKEN_BEDROCK="<your-bedrock-api-key>"
export AWS_REGION="us-east-2"
npx @openai/codex-security scan . --provider amazon-bedrock --model openai.gpt-5.6-luna
Amazon Bedrock also supports standard AWS access keys, profiles, web identity, container credentials, and the default AWS credential chain.
Local sign-in honors Codex’s configured credential backend, including a system keyring required by a managed device. Codex Security keeps login and scan credentials in the same private, persistent state directory.
If both a ChatGPT sign-in and an API key are available, interactive scans ask which credential to use. CI and other noninteractive scans keep the existing API-key precedence. Select a credential explicitly when needed:
npx @openai/codex-security scan . --auth chatgpt
npx @openai/codex-security scan . --auth api-key
To make your ChatGPT sign-in the automatic default, unset any configured API keys:
unset OPENAI_API_KEY CODEX_API_KEY
Scan history is stored in the Codex Security workbench state directory. If that
directory cannot be written, set CODEX_SECURITY_STATE_DIR to a writable
directory outside the repository.
findings list [repository] shows open findings across a repository’s scans
and identifies findings not confirmed in its latest scan.
scans compare BEFORE_SCAN_ID AFTER_SCAN_ID automatically matches findings by
root cause, reuses saved matches, and identifies new, persisting, reopened,
resolved, or unknown findings. Missing findings remain unknown when coverage is
incomplete or their original location was not reviewed.
Verbose diagnostics
Add --verbose to print scan diagnostics to stderr:
npx @openai/codex-security scan . --verbose
CODEX_SECURITY_LOG_LEVEL=debug also enables diagnostics;
LOG_LEVEL=debug is its fallback. JSON results remain on stdout.
Verbose diagnostics may contain sensitive data. Review local logs before sharing them. Saved failure summaries, bulk-scan receipts, and the interactive dashboard omit messages that contain recognizable credentials.
Use npx @openai/codex-security scans logs SCAN_ID to inspect saved session
events from a scan and its workers.
TypeScript SDK
import { CodexSecurity } from "@openai/codex-security";
const security = new CodexSecurity();
const result = await security.run(".");
await security.run(".", {
mode: "deep",
workers: 2,
subagents: 0,
stopAfterNoNew: 3,
maxDiscoveryRuns: 10,
maxTimeHours: 1.5,
});
console.log(result.reportPath);
await security.close();
Containerized bulk scans
Use the official image and included Docker Compose configuration for noninteractive, resumable scans of repositories pinned to immutable Git revisions. See the container quick start for authentication, private result storage, and optional Ubuntu AppArmor hardening.
Pass --knowledge-base PATH to share security documents with every repository;
repeat the option for multiple files or directories.
Use --scan-prompt-file PATH to add shared scan instructions, and add a prompt
CSV column for repository-specific instructions. Use
--post-scan-prompt-file PATH to run a follow-up after each scan, including
incomplete or failed scans.
For complete command help, runtime defaults, native multi-agent worker limits, environment variables, deep-scan configuration, and SDK options, see the package README and the official CLI reference.