OpenAI Codex Security CLI: Hands-On With the New Tool
OpenAI open-sourced Codex Security yesterday. It’s an Apache 2.0 licensed CLI plus a TypeScript SDK that finds security vulnerabilities in your codebase, validates them in a sandbox to filter out false positives, and proposes patches. The release landed on Hacker News, Greg Brockman pointed at the thread, and the repo immediately started picking up stars.
I’ve been following this tool since it was called “Aardvark” back in March. The research preview was impressive in demos but hard to actually integrate into a real workflow. The open-source CLI changes that — you can now drop it into CI/CD, run it locally, or wrap it in your own tooling. I spent the morning running it against three projects of varying sizes to see what it actually catches in practice and where it falls short.
What Codex Security Actually Does
The core architecture is a three-stage pipeline: find, validate, patch. That sounds simple, but the validation stage is what separates this from static analysis tools.
Stage 1 — Find: The agent reads your codebase and identifies potential vulnerabilities. It’s not just pattern-matching for known CVEs — it understands application logic. It can spot things like a route handler that fails to validate user permissions before executing a database query because it traced the control flow end to end.
Stage 2 — Validate: This is where Codex Security earns its keep. For each finding, it spins up a sandbox, reproduces the vulnerability with a proof-of-concept exploit, and confirms whether the finding is actually exploitable. If the sandbox can’t trigger the issue, the finding is marked as a false positive and suppressed. This dramatically cuts noise compared to traditional SAST tools that love to flag theoretical issues that can’t actually be exploited.
Stage 3 — Patch: For validated findings, the agent generates a fix. The patch includes a diff, an explanation of the vulnerability, and a confidence score. Patches with high confidence scores are designed to be applied directly (with review). Low-confidence patches are treated as suggestions for a human to evaluate.
The whole pipeline runs as a single codex-security scan command. You point it at a directory, and it works. The TypeScript SDK lets you programmatically control the scanner, which is essential for CI/CD integration.
Installation and First Run
Setup takes about 30 seconds:
npm install -g @openai/codex-security
export OPENAI_API_KEY="sk-..."
codex-security scan ./my-project
The scanner auto-detects your project type (Node.js, Python, Go, Rust, and a few others are supported out of the box) and applies the appropriate analysis rules. No config file required for basic use, though you’ll want one for CI/CD to control severity thresholds and ignore rules.
On first run against a medium-sized Next.js project (~80 files, ~15K lines), the scan took about 4 minutes and reported 12 findings. Of those, 3 were validated as real issues, 6 were flagged as false positives by the sandbox, and 3 timed out during validation (the sandbox couldn’t reproduce the issue within the default 30-second timeout).
The 3 real findings were:
- An API route that accepted a user ID parameter without verifying the requesting user had permission to access that user’s data (IDOR vulnerability)
- A file upload endpoint that didn’t validate MIME types, allowing arbitrary file uploads
- A database query constructed with string interpolation instead of parameterized queries
All three were legitimate issues. The IDOR finding in particular was subtle — the route had an auth middleware, but the middleware only checked that the user was logged in, not that they owned the requested resource. A human reviewer might have missed it. Codex Security caught it because it traced the data flow from the route parameter through the database query and noticed the authorization gap.
What It Catches Well
After running it across three projects (a Next.js app, a Python FastAPI backend, and a Go CLI tool), here’s my assessment of what Codex Security is strong at:
Authorization bugs. This is where the tool genuinely shines. It models user roles and permissions across your codebase and catches cases where a route or function should be gated but isn’t. Traditional SAST tools struggle with this because authorization logic is highly application-specific. Codex Security’s ability to understand application context makes it better at spotting these.
Injection vulnerabilities. SQL injection, command injection, LDAP injection — if user input reaches a dangerous sink without sanitization, Codex Security usually catches it. It’s more thorough than grep-based scanners because it traces input through multiple function calls and transformations.
File operation risks. Path traversal, unsafe file writes, symlink attacks — the sandbox validation is particularly effective here because it can actually attempt to write outside the intended directory and confirm the vulnerability.
Hardcoded secrets. API keys, tokens, and passwords in source code are caught reliably. The tool also checks git history for secrets that were committed and later removed (something most secret scanners miss).
Where It Struggles
No tool is perfect, and Codex Security has clear limitations:
Business logic flaws. If your application has a vulnerability that’s correct from a code perspective but wrong from a business perspective — allowing users to apply discount codes multiple times, for example — Codex Security won’t catch it. It understands code, not business rules.
Dependency vulnerabilities with no code path to exploitation. The scanner checks package.json and requirements.txt for known vulnerable dependencies, but it doesn’t deeply analyze whether the vulnerable code path is actually reachable in your application. You’ll still get alerts for vulnerable dependencies your app doesn’t use.
Rate of false positives on dynamic languages. Python and JavaScript projects generate more false positives than Go or Rust projects. The sandbox validation filters most of them out, but noisy output is still noise. Expect to spend time triaging findings on dynamic-language projects.
Performance on large monorepos. The 4-minute scan on a small project is fine. On a monorepo with 200K+ lines of code, the scan took 28 minutes and timed out on about 20% of findings during validation. OpenAI recommends running it on changed files only in CI/CD for large projects, but that workaround means you might miss cross-file vulnerabilities.
Limited language support. The officially supported languages are JavaScript/TypeScript, Python, Go, and Rust. Java, C#, Ruby, and PHP are “experimental” and produce noticeably worse results. If your stack is outside the Big Four, you’ll want to wait for broader language support.
CI/CD Integration Tips
The real power of Codex Security is in CI/CD, where it runs automatically on every PR. Here’s what I’ve learned from setting it up:
Run on changed files, not the whole repo. The --diff flag limits the scan to files changed in the current branch, which keeps scan times under 2 minutes for typical PRs:
codex-security scan --diff origin/main...HEAD
Set severity thresholds per pipeline. Don’t block merges on low-severity findings. Block on critical and high, warn on medium, and ignore low:
# .codex-security.yml
pipeline:
pr_check:
block_on: [critical, high]
warn_on: [medium]
Use the SDK for custom integrations. The CLI is fine for GitHub Actions, but if you have a custom CI system, the TypeScript SDK gives you full control:
import { CodexSecurity } from '@openai/codex-security';
const scanner = new CodexSecurity({ apiKey: process.env.OPENAI_API_KEY });
const report = await scanner.scan({
path: './src',
diff: 'origin/main...HEAD',
minSeverity: 'medium',
});
for (const finding of report.findings) {
if (finding.validated) {
console.log(`[${finding.severity}] ${finding.title}`);
console.log(finding.patch?.diff);
}
}
Cache the sandbox. The sandbox initialization takes 10-15 seconds. If you’re running scans frequently, cache the sandbox image to cut cold-start time.
Don’t run it on every commit to feature branches. Configure it to run on PR creation and PR updates. Running on every push wastes API credits and CI minutes.
Cost
OpenAI charges for Codex Security usage based on the tokens consumed during the find and validate stages. Based on my usage across the three test projects:
- Small project (5K lines): ~$0.80 per scan
- Medium project (15K lines): ~$2.50 per scan
- Large monorepo (200K lines, full scan): ~$18 per scan
The --diff mode on PRs typically costs $0.50-1.50 per scan, which is reasonable for most teams. If you’re running it on every PR for a team of 10 developers each opening 3 PRs per week, you’re looking at roughly $90-270 per month. Compare that to a single security engineer’s salary, and it’s clearly worth it — if it catches even one serious vulnerability per month.
The open-source license means you can self-host the scanner if API costs become a concern, but you’d need to provide your own sandbox infrastructure. For most teams, the hosted version is the practical choice.
How It Compares to Alternatives
Semgrep. Semgrep is faster and cheaper (free for open-source rules), but it’s pattern-based — it catches known vulnerability patterns, not novel logic bugs. Codex Security catches things Semgrep misses (like the IDOR issue I described) but costs money and takes longer. They complement each other well: Semgrep for fast pattern matching, Codex Security for deep analysis.
Snyk Code. Snyk has better dependency scanning and a larger rule database. Codex Security has better application-level analysis. If you’re already using Snyk, Codex Security adds coverage for vulnerability classes Snyk struggles with.
GitHub Code Scanning (CodeQL). CodeQL is excellent for the languages it supports and integrates deeply with GitHub. Codex Security covers fewer languages but requires less setup and produces fewer false positives. Teams on GitHub will probably use both.
Manual pentesting. Nothing replaces a skilled human pentester for business logic and novel attack vectors. Codex Security automates the routine stuff — injection, auth bypass, path traversal — so your security team can focus on the harder problems.
Bottom Line
Codex Security is genuinely useful, especially for teams that don’t have dedicated application security engineers. It catches real vulnerabilities that static analysis tools miss, the sandbox validation cuts false positives to a manageable level, and the CLI is straightforward to integrate into CI/CD.
It’s not a replacement for a security review, and it won’t catch business logic bugs. But as an automated first line of defense, it’s good. The open-source license and the --diff mode make it practical to adopt incrementally — start with critical-severity blocking on PRs and expand from there.
One note on self-hosting: the Apache 2.0 license means you can run the scanner on your own infrastructure without paying OpenAI per-scan costs. You’ll need to provide your own sandbox environment (Docker works fine) and point the scanner at it via the --sandbox-url flag. For teams that run hundreds of scans per day, self-hosting pays for itself quickly.
Sources:
- OpenAI: Codex Security research preview (openai.com/index)
- explainx.ai: Codex Security CLI open-source breakdown (explainx.ai/blog)
- Cybersecurity News: Codex Security launch coverage (cybersecuritynews.com)
- Hacker News: Discussion thread (news.ycombinator.com)