Security engineering · Platform architecture
Building Scan Factory: an orchestrated platform for AI-powered security scanning and automated remediation.
I just shipped the feature I am most proud of so far. It makes security scanning repeatable across repositories, with no manual setup, no environment wrangling, and no hand-coordinated analysis, and then hands developers a reviewed path to the fix.
The context
The idea was to stop starting scans by hand.
Security scanning is one of those jobs where the analysis is the interesting part, and everything around it is overhead. Someone has to pick the repository, check out the right commit, prepare an environment, run the tool, collect the output, and make sure the results end up somewhere a human will actually read them. Repeat that across repositories and teams, and the process stops being repeatable.
I wanted a centralized platform that could accept scanning requests, provision isolated execution environments, run security analysis with Codex Security CLI, and collect the results in one place.
But I did not want to stop at identifying vulnerabilities.
Once a scan is complete, a security analyst should be able to review the findings and trigger a second workflow. That workflow uses our own custom agent harness to investigate and fix the vulnerabilities, then opens a GitHub pull request with the proposed changes. The final review and merge decision stays with the developer.
I call this platform Scan Factory.
At a high level, it consists of two independent execution workflows:
- Security scanning using Codex Security CLI.
- Automated vulnerability remediation using our custom agent harness and internally trained coding model.
Both workflows share the same orchestration infrastructure, but they run in separate, isolated execution environments. That separation is the whole design.
“Find a vulnerability” and “change production code” are two different jobs. They get two different workflows, two different sandboxes, and two different permission boundaries.
Section 01
Architecture: a control plane and an execution plane.
I approached Scan Factory as an event-driven orchestration platform with a clear separation between the control plane and the execution plane.
The control plane manages workflows, creates tasks, dispatches executions, tracks progress, and collects results. The execution plane performs the actual work inside isolated sandbox environments.
Control plane
Execution plane
1.1Work request sources
The system is designed to accept work from multiple sources, but right now it supports two of them.
Available today
- Security engineers can request scans manually.
- Developers can request a security assessment for their repositories.
In both cases, the team or repository is onboarded first, then scans are requested through the Scan Factory API.
Planned next
- GitHub webhooks triggered by pull requests or repository changes.
- CI/CD pipelines requesting scans as part of the build process.
- Scheduled workflows for periodic security assessments.
Whatever the source, every request goes through the same Scan Factory API. That is deliberate. A consistent entry point means the rest of the system does not care where a request came from, so adding a new source later is an integration task, not a redesign.
1.2Workflow Service
The Workflow Service defines, creates, and manages workflows. I distinguish between a workflow definition and a workflow execution.
A workflow definition describes what needs to happen. A security scanning workflow, for example, contains these steps:
- 01Check out the repository.
- 02Prepare the execution environment.
- 03Configure Codex Security.
- 04Execute the security scan.
- 05Collect findings.
- 06Publish the results.
An individual workflow execution represents an actual request to run those steps against a particular repository and commit. That distinction lets me reuse the same definition across many repositories without creating a new workflow for every scan.
The service persists workflow definitions, task metadata, execution status, and progress. When a security engineer submits a scan request, the Workflow Service creates a task with an initial state of QUEUED. It does not immediately start the agent or provision a sandbox; it makes the task available for asynchronous execution.
1.3Dispatch Loop
The Dispatch Loop assigns ready tasks to available execution capacity. It continuously monitors the task queue for eligible work. When a task becomes ready, it:
- Identifies the task and its associated workflow.
- Checks execution limits and available capacity.
- Atomically claims the task.
- Assigns an execution worker.
- Requests that the Execution Manager provision a sandbox.
- Records the execution identifier against the task.
The Dispatch Loop does not execute the security scan itself. It coordinates execution and ensures tasks are assigned to the appropriate workers. Task leases and execution identifiers prevent multiple workers from accidentally executing the same task.
1.4Execution Manager
The Execution Manager handles the lifecycle of execution environments. This component matters because I do not want security scanning or remediation agents running directly inside the orchestration infrastructure. Every execution gets its own isolated sandbox.
The Execution Manager provisions the environment, injects the required configuration, starts the execution process, monitors its lifecycle, and terminates it when the task finishes. A big thank you to our infra team for helping build the sandbox, with the resources developers rely on day to day and least-privilege permissions baked in.
1.5Event Subscriptions
Not every workflow needs to execute immediately. Some wait for external events such as:
- A repository becoming available.
- A pull request receiving additional commits.
- A previous workflow completing.
- An analyst approving a remediation request.
- A retry becoming eligible.
The Event Subscription component listens for these events and wakes the relevant waiting tasks. Once the required condition is satisfied, the Workflow Service can transition the task back to READY, allowing the Dispatch Loop to pick it up. This keeps orchestration event-driven instead of relying entirely on continuous polling.
Section 02
Workflow one: security scanning with Codex Security CLI.
The first workflow identifies vulnerabilities across repositories. I decided to use the dedicated Codex Security CLI directly rather than launching the general Codex CLI and asking an agent to initiate a security scan. That keeps the scanning execution focused and avoids introducing an unnecessary agent orchestration layer.
Step 1Submit a scan request
A security engineer or developer submits a request through the Scan Factory API. The request contains repository details and the configuration required for the analysis.
{
"repository": "company/payment-platform",
"branch": "main",
"commit_sha": "abc123",
"scan_type": "full_repository",
"engine": "codex_security",
"deep_scan": true,
"additional_context": {
"focus": "authentication service",
"instructions": "Investigate authorization bypasses and insecure session handling."
}
}The API authenticates the requester, validates repository permissions, and forwards the request to the Workflow Service. The Workflow Service creates a scan task, persists its metadata, and immediately returns an acknowledgement rather than waiting for the scan to complete.
{
"task_id": "scan-12345",
"status": "QUEUED"
}The task is now ready for asynchronous processing.
Step 2Dispatch the task
The Dispatch Loop identifies the newly created task and claims it for execution. It checks available execution capacity and sends the task to the Execution Manager, which creates a new execution instance associated with the task.
At this point the system has two separate identifiers:
task_idrepresents the business operation.execution_idrepresents the actual sandbox execution.
This separation is useful because a task may have multiple execution attempts if something fails.
Step 3Provision the sandbox
This is where the isolated execution environment comes in. Rather than installing every dependency from scratch, I maintain a pre-configured execution image containing the required runtime dependencies and Codex Security CLI. When a scan task is dispatched, the Execution Manager provisions a fresh sandbox from that image.
The sandbox receives only the permissions required for that particular execution:
For repository access, I use a dedicated service identity with narrowly scoped permissions rather than copying a developer's personal credentials into the environment. The sandbox only receives read access to the repository being scanned. Credentials are injected at runtime and are not baked into the execution image, so every scan runs inside an isolated environment with a controlled security boundary.
Step 4Execute Codex Security CLI
Once the sandbox is ready, the Execution Manager prepares the repository: it checks out the requested branch and commit, configures the scan parameters, and starts Codex Security CLI. The CLI is already available inside the environment, so there is no need to launch the general Codex agent runtime.
npm install -g @openai/codex-security
codex-security login
codex-security scan .The actual authentication and scan configuration follow the supported CLI configuration. That includes API-key authentication, the required Cyber Access entitlement, model configuration, reasoning level, deep-scan setting, and additional analysis context.
The important point is that these settings come from the workflow configuration rather than being entered manually by an engineer every time.
Step 5Security analysis
Once the scan starts, Codex Security performs the analysis against the checked-out repository, following the security analysis lifecycle:
- 01Repository preparation and codebase understanding
- 02Identification of components and attack surfaces
- 03Threat modelling
- 04Code investigation
- 05Identification of candidate vulnerabilities
- 06Validation of potential attack paths
- 07Generation of findings and supporting evidence
If the additional context focuses on authentication, the analysis can concentrate on authentication and authorization-related code paths. The resulting findings include vulnerability descriptions, affected code, severity, attack paths, and supporting evidence.
Step 6Track execution progress
I do not want the Dispatch Loop occupied while a security scan is running. Once the Execution Manager starts the process, it returns the execution reference and the task transitions to RUNNING. The execution environment operates independently and emits events that are consumed by the Event Handler.
{
"event": "scan.progress",
"task_id": "scan-12345",
"execution_id": "exec-789",
"stage": "THREAT_MODELING",
"progress": 35
}The Event Handler updates the corresponding task state in the Workflow Service. The same mechanism handles events such as:
- Scan started.
- Repository checkout completed.
- Threat modelling completed.
- Findings discovered.
- Scan completed.
- Scan failed.
This allows the platform to expose execution progress without keeping the original API request open.
Step 7Collect and persist scan results
Once Codex Security finishes, the Result Collector retrieves the generated findings and supported artifacts, normalizes the output into a consistent format, and persists it.
I separate execution metadata from the actual scan artifacts. The database stores:
- Task identifier.
- Repository and commit.
- Execution status.
- Scan configuration.
- Vulnerability counts.
- Artifact references.
- Execution timestamps.
Detailed reports and other artifacts live in durable object storage. Once the results are successfully persisted, the Workflow Service marks the scan task as COMPLETED. The Execution Manager then terminates the sandbox and revokes temporary credentials. The first workflow is complete.
Section 03
The analyst dashboard: findings deserve a real interface.
I wanted the output of the scanning workflow to be accessible through a central interface rather than leaving engineers to inspect CLI output or download individual reports. The Scan Factory dashboard provides a centralized view of scan executions and their findings.
When an analyst or developer opens a completed scan, they can review:
For example, an analyst might see:
| Severity | Findings |
|---|---|
| Critical | 1 |
| High | 2 |
| Medium | 4 |
| Low | 3 |
| Total | 10 |
These numbers are illustrative. The analyst can inspect individual findings to understand the potential impact and determine which issues should be addressed.
More importantly, the dashboard provides an action to initiate automated remediation. I deliberately keep this as a separate workflow. Finding a vulnerability and modifying code are two different responsibilities, and I do not want the scanning process to automatically make changes to a repository. The analyst reviews the findings and explicitly triggers remediation.
Section 04
Workflow two: automated vulnerability remediation.
For remediation, I do not use Codex Security CLI or the general Codex CLI. I use our own custom agent harness, backed by an internally trained coding model. The harness is designed specifically for code investigation and vulnerability remediation, with its own execution lifecycle, configured skills, and restricted permissions.
The orchestration infrastructure stays the same. The execution environment and agent runtime change.
Step 1Trigger remediation from the dashboard
The analyst reviews the findings and selects the vulnerabilities that need remediation, then initiates a request for those findings. The dashboard sends a new request to the Workflow Service.
{
"repository": "company/payment-platform",
"source_scan_id": "scan-12345",
"commit_sha": "abc123",
"selected_findings": [
"finding-001",
"finding-002",
"finding-003"
],
"workflow": "automated-remediation"
}The Workflow Service creates a new remediation task, completely separate from the original scan, but holding a reference to the source scan and the findings the analyst selected. That gives us traceability between the vulnerabilities identified and the remediation work initiated.
Step 2Dispatch the remediation task
The Dispatch Loop picks up the new task, identifies the corresponding workflow definition, and assigns it to an available execution worker. The Execution Manager is then instructed to provision a separate sandbox.
I intentionally do not reuse the original scanning sandbox. The remediation workflow has a different security profile and requires different permissions.
Step 3Provision the remediation sandbox
The Execution Manager provisions another isolated environment using the remediation execution image. This environment contains:
- Our custom agent harness.
- The internally trained coding model integration.
- Configured remediation skills.
- Required development and testing tools.
- Repository checkout utilities.
- Restricted GitHub access.
- Runtime and execution policies.
The agent receives the repository at the relevant commit, along with the validated findings from the original scan. Its GitHub permissions are limited to the operations required to create a remediation branch and submit a pull request. It cannot merge code into the target branch.
The objective is to let the agent propose changes without giving it control over the final code integration process.
Step 4Execute the custom remediation agent
Once the sandbox is ready, the Execution Manager starts our custom agent harness. The harness receives the remediation task and its associated context:
- Repository information.
- Source commit.
- Selected vulnerability findings.
- Affected files and code locations.
- Attack paths and evidence.
- Remediation guidance.
- Configured skills and execution policies.
The agent then investigates the relevant code paths. It does not simply apply a suggested patch without understanding the surrounding implementation. Its workflow is:
- 01Understand the vulnerability and its cause
- 02Inspect the affected code and dependencies
- 03Identify the appropriate remediation strategy
- 04Implement the required code changes
- 05Run configured tests and validation checks
- 06Review the changes against the original findings
- 07Prepare a remediation summary
The agent uses the configured skills and available tools to perform these operations inside the sandbox.
Step 5Create a GitHub pull request
Once the agent has completed its work and the configured validation checks have passed, it prepares the changes for review. It creates a separate Git branch, commits the proposed fixes, and uses its restricted GitHub permissions to create a pull request against the target repository.
The pull request contains:
- Summary of the identified vulnerabilities.
- Findings addressed.
- Files modified.
- Explanation of the changes.
- Validation and test results.
- Any unresolved findings or limitations.
The pull request is the handoff point between automated remediation and developer-controlled code integration. The agent cannot merge it. Its responsibility ends with preparing and submitting the proposed changes.
Step 6Developer review and merge
The developer receives the pull request and follows the normal code review process. They can review the generated changes, inspect the implementation, run additional tests, request amendments, provide feedback, approve the changes, and merge when satisfied.
If amendments are needed, the developer can make them manually or initiate another remediation iteration. The final decision to accept and merge always remains with the developer. That creates a clear separation between automated vulnerability remediation and human-controlled code integration.
Section 06
Failures are part of the design, not an edge case.
Because Scan Factory executes asynchronous workloads across isolated environments, failure handling has to be designed in from the beginning. Some possible scenarios:
| Scenario | Expected behaviour |
|---|---|
| Sandbox provisioning fails | Retry provisioning |
| Repository checkout fails | Refresh or revalidate credentials |
| Codex Security process crashes | Capture logs and retry according to policy |
| Scan exceeds execution limits | Terminate and mark as timed out |
| Worker becomes unavailable | Recover task after lease expiry |
| Result upload fails | Retry artifact upload without rerunning the scan |
| Remediation tests fail | Preserve changes and report validation failure |
| GitHub PR creation fails | Retry submission without repeating the entire remediation |
I also separate task state from execution attempt state. A single task can have multiple attempts, but each attempt receives its own execution identifier. This makes it easier to recover from failures without losing the original task history.
For example, if a security scan completes successfully but uploading its report fails, I do not want to execute the entire scan again. Result publishing is retried independently. Similarly, remediation execution and pull request creation persist enough state to avoid repeating code modifications when only the final GitHub operation fails.
Section 07
Isolation is the security boundary.
Because this platform works with application source code and security findings, isolation is a fundamental requirement. I apply different permission boundaries to the two execution workflows.
Scanning environment
- Read-only repository access.
- Required Codex Security authentication.
- Restricted network access.
- Workspace-scoped filesystem permissions.
- Execution and resource limits.
Remediation environment
- Access to the target repository.
- Permission to create branches and commits.
- Permission to create pull requests.
- Access to approved development tools.
- Configured agent skills.
- Restricted network access.
- Execution and resource limits.
Neither environment receives unrestricted access to the developer's credentials or the broader organizational environment. The remediation agent cannot merge code or bypass the developer review process. Both environments are destroyed after their respective executions, and temporary credentials are revoked.
This is what allows one orchestration infrastructure to support different workloads without giving every agent the same level of access.
Section 08
The complete lifecycle.
Putting everything together, a Scan Factory request moves through two lanes on shared infrastructure.
Lane A · security scanning
Execution Manager
Uses the scan execution image.
Scan sandbox
Read-only repo access, temporary credentials.
Codex Security CLI
Threat modelling, code investigation, evidence.
Result Collector
Normalized and persisted.
Findings persisted
Metadata in the database, artifacts in object storage.
Analyst dashboard
Status, severity, attack paths, suggested remediation.
Lane B · remediation
Remediation triggered
Separate task, traceable to the source scan.
Execution Manager
Uses the remediation execution image.
Remediation sandbox
Branch and PR permissions only, no merge.
Custom agent harness
Investigate, fix, validate.
Validation and tests
Configured tests and validation checks.
GitHub pull request
Findings, files changed, evidence, limitations.
Developer review & merge
The final decision stays human.
Throughout both workflows, the Event Handler records progress and updates task state. The dashboard consumes the persisted scan and remediation data, so the full lifecycle stays visible in one place.
Section 09
What I built first.
I approached implementation incrementally, in four phases.
Phase 1
Security scanning infrastructure
- Scan API
- Workflow Service
- Workflow definitions and task state
- Dispatch Loop
- Sandbox execution image
- Codex Security CLI integration
- Scan result collection
Submit a repository scan request and receive a complete security report without touching the CLI.
Phase 2
Analyst dashboard
- Scan history
- Vulnerability findings
- Severity-based filtering
- Attack paths and evidence
- Finding selection
- Remediation trigger
Review findings in one interface and decide what is worth fixing.
Phase 3
Automated remediation
- Remediation execution image
- Custom agent harness
- Remediation skills and permissions
- Findings and repo context handoff
- Code changes and validation
- GitHub branch and PR creation
Turn selected findings into a reviewable pull request.
Phase 4
Orchestration at scale
- Distributed dispatch workers
- Concurrency management
- Execution leases and recovery
- Event-driven wake-ups
- Retry policies and observability
- Multi-repository, multi-team scale
Keep the same execution model as usage grows.
Section 10
Results after three weeks in production.
Scan Factory is still new. It went live within the last three weeks, and in that time it has completed more than 150 scans and proposed remediation for the vulnerabilities they found.
150+
scans completed in the first three weeks
- Repeatable scans. Security engineers and developers request a scan, and it runs without anyone setting up environments or coordinating the analysis.
- Isolation held up. Every scan and every remediation ran in its own sandbox. Nothing ran inside the orchestration infrastructure.
- One platform, two workflows. Security analysis with Codex Security CLI and remediation with our custom agent harness share task management, dispatching, execution management, event handling, and result collection.
- Findings and fixes in the right hands. Analysts get the findings. Developers get the generated fixes as GitHub pull requests.
- Developers stay in control. The agent investigates, modifies code, validates changes, and prepares the pull request. The review and merge stay with the developer.
The central idea: separate orchestration from execution.
The orchestration layer manages the lifecycle of work. Isolated execution environments do the actual tasks. That separation is what makes security scanning and vulnerability remediation repeatable, isolated, and auditable, and it is the part of this system I would keep if I had to build it again from scratch.
Keep reading
Durable execution is the real reliability layer for AI agents
Why checkpointing, replay-safe steps, and idempotent side effects are the foundation of long-running agent workflows.
Read the article