Add Codex exec auth flow and sandboxed analysis support - #851
Conversation
|
Ran this against my own code base |
|
Hi - this is a substantial piece of work, thanks! A few observations/questions if I may: Bug
Design questions1. What does the Codex CLI path provide over the existing OpenAI API path? RAPTOR already supports OpenAI models via the external LLM dispatch - set If the value is subscription-based access without an API key, that's worth understanding but the tradeoffs (below) should be visible to the operator, not silent. If the value is that Codex can read the full repository via It would help to have the intended use case spelled out so the design choices make sense to future readers. 2. Defense envelope is bypassed for Codex dispatch The canary probe ( The external LLM and CC paths both get structural defenses verified by probe. The Codex path doesn't, and nothing tells the operator. Suggestion: if Codex can't support the envelope, surface the weaker posture in operator-facing output (not just JSON metadata) and require something like 3. No cost or budget control
Suggestion: a finding-count cap defaulting lower for Codex mode, or at least a banner like "Codex mode: analysing N findings (no cost tracking available)" so operators know what they're getting into. 4. Single-pass unverified verdicts Every post-analysis quality gate is disabled: retry, consensus, judge, aggregate, group. The result is single-pass unverified verdicts on security findings which is a meaningful reliability gap compared to every other dispatch path. Suggestion: enable the self-consistency retry stage at minimum as it's lightweight (re-dispatches only contradictory or low-confidence results) and catches the worst single-pass errors. If that's not feasible here, an operator-visible note in the report summary that verdicts are single-pass would help. None of this is meant to block the direction and the sandbox work and auth delegation are great pieces of work. But taken together, the Codex path has fundamentally weaker assurances than the paths it sits alongside, and nothing surfaces that to the operator at run time. A finding-count cap, enabling retry, and gating on What do you think? |
|
@grokjc - thanks for looking! 🙏 If this direction is adopted for future then it needs more work to fit the existing sequence in the pipeline - again I can probably see how to adopt that in a better way. Its a first attempt, and although the connection works, its done with very little understanding of the whole codebase and the reasons behind how its developed - your comments here are really helpful with that. Your other observation here is important too - the target repo under inspection is not to be trusted - and there needs to be some amount of work to ensure the code under the microscope is not affecting the analysis with hidden prompts in any way. I can certainly keep that separation in mind. I think what this points to is that I need to also get my head around how the current structure works to derisk that. Or like you suggest in various areas - be super clear with the user that there is a risk. The use case:For me its just to be able to use this tool with a lowly ChatGPT Plus account, where I dont think I can generate API keys. As a result I thought I would take a crack at setting it up and seeing what it was like. One possible use case I kind of wondered about, was consensus between LLM's having seen the same prompts, or comparative sample exploit code. But this isnt something I am actually working on, just theorizing. The bugI think can probably fix that up - I will take a look! Seems low effort.
I think maybe I should just keep chipping away - but I am also conscious that this change will become quite weighty and difficult to review. If I carry on on my own fork branch and see how it looks there, then maybe I can break it out into meaningful chunks too. I will let you know if this is necessary. In any case - this is all "learning by doing" so appreciate the comments! |
|
Having taken another look at this I think some of your changes here are genuine improvements to main with no Codex dependency whatsoever and splitting them out would shrink the review surface and get value merged sooner:
The If you fancy landing some or all of that as a separate PR I'd appreciate it! CodeQL The
On the Codex-as-agent point One thing worth keeping in mind as you look at the envelope integration: Thanks for the support! |
|
Yeah - sounds sensible 👍 I will split the commits up a bit and maybe retarget the effort towards that then - to be able to test it out on my own set up I will need to either (1) rebase the Codex connection on the new logging/annotion/mocks fixes and test - or - (2) part with the cash for some claude tokens... - or - maybe also hook up claude to my GPU in my home lab... its all possible tho! Testing across setups will represent other use cases, and hopefully introduce robust changes.. 🤞 Probably be able to look at it over the weekend, but might be next week before I have the change in place. Happy to help tho! 😉 |
|
Echo'ng what @grokjc said here, this is bloody epic work!! thank you |
Add an analysis-only Codex CLI dispatch path for agentic findings. The bridge invokes authenticated codex exec with read-only, ephemeral execution, stdin-based prompts, structured output schemas, sanitized debug diagnostics, and auth checks before dispatch. Wire --codex-exec through the agentic CLI and orchestrator while disabling exploit, patch, retry, consensus, judge, aggregate, and group LLM stages for this PR2 path. Includes coverage for Codex schema conversion, subprocess handling, auth failure, CLI routing, and orchestrator dispatch behaviour.
Centralize dispatch-mode labels, report metadata, Codex billing flags, and analysis-only stage gating behind a small immutable policy helper. This keeps the existing orchestration pipeline order and dispatch branches intact while making Codex, Claude Code, and external LLM mode behavior easier to review and test.
|
Good progress, thanks! Two gaps remain from the prior review, plus a few new things... No fallback when all Codex calls fail The CC-fallback block after the analysis dispatch loop is gated on Defense probe still silently skipped The canary probe verifies a model can parse the defense envelope (XML tags, datamarking, nonce). For Codex, Two options: either wire up a synthetic probe against Schema conversion misclassifies two production fields
The production The fix is to match the type keyword at the start of the description rather than anywhere in the body. The compact format is always
The But beyond that, the change doesn't actually do anything. Here's how the existing mechanism works: The pid1 shim ( The PR's explicit I'd say drop these two hunks from this PR entirely. If you want them as extra safety, that's a conversation for a separate PR, but given how the propagation already works they're adding a redundant write that could mislead future readers into thinking the allowlist doesn't cover this case.
Smaller items
This branch almost certainly needs a rebase onto current main now that #860 and #861 have landed. Should be clean since those PRs touched non-overlapping areas. That's a lot of text to say there really isn't that much left to fix. Thanks for your work on this! 👍 |
|
Got into some work - so I am distracted at the moment - but I will come back to this soon! Thanks @grokjc for checking over the last update tho - will digest comments and get it ready |
|
I took the liberty of merging the recent changes for you, which turned out to be a pain 😄 We got there in the end ... this will teach me to refactor things! |
Thanks for doing this!! Will pick up the changes and continue soon! |
Summary
This branch adds an authenticated
codex execanalysis path alongside the existing Claude Code / external LLM orchestration paths, and fixes the sandbox handling needed for Codex and CodeQL tool subprocesses.It also improves run-level logging ergonomics so operators can reduce console noise without changing logger call sites or weakening audit/file logging.
What Changed
core/startup/codex.py.--codex-execanalysis mode for agentic/autonomous LLM analysis flows.packages/llm_analysis/codex_dispatch.pyto callcodex execwith schema-constrained JSON output.run_untrusted_networkedwith a narrow host allowlist and scoped Codex config/auth paths.agentic --log-levelto reduce console noise without changing logger call-site levels._RAPTOR_TRUSTEDis an internal pid1-shim marker, stripped before target execution, and is not equivalent to--trust-repo.Why
Codex exec and CodeQL are RAPTOR-owned tool subprocesses, but they execute inside RAPTOR’s sandbox. That means they need a careful two-part contract:
_RAPTOR_TRUSTED=1.Without this, sandboxed tool runs can fail with:
Codex also needs controlled access to its existing auth/config state and network access to OpenAI/Codex endpoints.
CodeQL needs the same internal shim treatment during database creation and query execution while preserving strict environment sanitisation before target build execution.
Validation
Focused Python validation passed:
Result:
Manual validation:
vectorAddtarget built under CodeQL tracing.vectorAdd.grm-rswas scanned with combined Semgrep + CodeQL + Codex exec analysis.Full pytest was also attempted locally:
That did not complete cleanly in this local environment. The failures were concentrated around environment/tooling constraints, including local socket bind restrictions, a missing
python2fixture dependency for CodeQL Python e2e tests, and optional tool integration tests.Notes
This branch intentionally does not include repo-local
.tools/or.gitignorechanges. CodeQL should be supplied as a system/operator dependency and pointed to viaCODEQL_CLIor--codeql-cli.This branch also intentionally does not retain verbose CodeQL log-tail collection. That was useful while diagnosing local build failures, but it was too much diagnostic collection for the PR surface.
Follow-up worth considering: audit other tool integrations such as AFL++, Semgrep, Frida, GDB/rr, Coccinelle, jadx, and similar tools for the same sandbox/tool-env pattern.