Running OpenCode or Codex in CI

November 30, 2026 · 9 min read · By the bestcloudagents team

bestcloudagents is operated by Replicas, one of the products discussed here. Every claim about a product comes from its own docs or pricing; see how we score.

Running OpenCode or Codex in CI is a plumbing problem before it is an automation opportunity. Reliable headless execution requires a non-interactive entry point, safe credential injection, constrained permissions, and output a pipeline can interpret. Once those foundations are in place, the same machinery can support PR reviews, parallel coding tasks, and work triggered from existing engineering tools.

What "headless mode" actually means for OpenCode and Codex, and why CI demands it

An interactive coding agent assumes someone can approve a tool call, resolve ambiguity, or interrupt a runaway action. CI has no such fallback. A job must start with enough context and authority to finish without waiting for a person, yet remain constrained when its interpretation is wrong.

Both OpenCode and Codex CLI provide purpose-built headless entry points. Those entry points address invocation, but the surrounding workflow must supply credentials, establish permission boundaries, and interpret the result. These are separate requirements with different failure modes. A command that starts without trouble can still expose a secret, do more than it was meant to, or leave the pipeline unable to tell whether the job finished or failed.

Non-interactive invocation: the flags and subcommands that actually start a headless run

OpenCode starts a headless task with opencode run "<prompt>". A representative CI command is opencode run --standalone --archived --format json "<prompt>", with the provider key injected as a secret. The --archived flag keeps CI sessions out of the interactive session list. OpenCode 2.2.0 removed the first-party GitHub Action, so V2 workflows call the command from their own YAML.

Codex uses codex exec, also available as codex e. A representative invocation is codex exec --sandbox workspace-write --json --output-last-message report.md "<prompt>". It runs to completion without prompting, prints the result, and returns a process exit code. The older --full-auto flag has been removed in favour of --sandbox workspace-write and now produces an error.

These commands establish the shape of a CI step without prescribing the task itself. The prompt tells the agent what to do, while the options around it control how it runs and reports its work. Neither command replaces the CI job’s security configuration.

Credential handling without leaking secrets into logs

Both tools take credentials through environment variables, which a CI secrets manager can inject. OpenCode defaults to bringing an API key for the chosen model provider. The tool is free and has a permissive license, while model usage goes through the account behind that key. This separates the agent installation from the authority used to call a model.

For either tool, the operational rule is to scope the CI key to the minimum model and project access the job needs. Rotation should be separate from keys used interactively. A leaked CI secret has a broader blast radius than a local session key, so a shared credential also ties otherwise separate workflows to the same exposure. Secret injection is not sufficient if the workflow subsequently prints the value into its logs.

For genuinely air-gapped repositories, OpenCode can use a local model so that nothing leaves the CI environment. That requires significant VRAM. It is an option for high-sensitivity code where a hosted model API is not acceptable, rather than a change to the basic headless invocation pattern.

Sandbox and permission models: what each tool constrains when no human is present

An unattended agent with broad token rights and no approval policy can act beyond the intended task. The outer execution boundary comes first. Both tools should run inside a CI runner or container that is already sandboxed, with their own controls as another layer.

Codex CLI offers read-only, workspace-write, and danger-full-access sandbox modes through --sandbox, or -s. For a CI job that needs to edit files, workspace-write is the appropriate default. It permits workspace changes but prevents access to the rest of the filesystem and outbound network calls. A job that only examines code has a different requirement from one expected to implement a fix, so the mode should follow the assignment.

OpenCode instead uses allow, ask, and deny permission rules, with no built-in OS-level sandbox. Its default Build Mode lets it read, write, and run commands. Plan Mode restricts file edits but still allows bash commands, so it is not an isolation boundary for review work. Running it in Docker with limited sandboxing provides the documented CI approach.

The dangerous combination is concrete. codex exec with push rights to main, deploy credentials, and no approval policy is an unattended agent with production access. The safe operating pattern is minimum token scope, a container, and human review of the resulting pull request before merge.

Machine-readable output and exit codes: parsing results reliably in a pipeline

A pipeline needs to distinguish a completed task from failure, timeout, or refusal. Readable prose alone is not a reliable gate. For both tools, the process exit code should be the primary pass/fail signal, while structured output supplies supplementary data for logging, comments, and routing. Successful execution is also distinct from human acceptance of the proposed code.

Codex’s --json option emits newline-delimited JSON events throughout a run. The workflow can save its final summary separately through --output-last-message <path> as plain text for a PR comment or Slack response. OpenCode’s --format json supplies machine-readable JSON output. The two output formats should not be assumed to share a schema.

For OpenCode reviews, the documented reporting pattern asks the agent to write report.md. The CI job then posts that file through the Git provider’s API as a PR comment. This separates the review artifact from execution telemetry. The pipeline can use the exit status to govern the step while retaining a concise report for the person reviewing the result.

A working PR-review pipeline using OpenCode in CI

A PR review is a useful first complete workflow because it does not require repository write access. The documented setup clones the repository, installs OpenCode in Docker with limited sandboxing, and injects auth.json through an environment variable. It then passes the review prompt, collects report.md, and posts the file back to the Git provider. GitHub Actions, GitLab CI, and Bitbucket Pipelines can all express this sequence in YAML.

The prompt gives the review a specific method. It asks OpenCode to read an architecture or context file first, run git diff $BASE_BRANCH...HEAD, and examine the full changed files and related files. It then applies a conservative filter, requiring every concern to be verified before it is flagged and excluding style complaints and hypotheticals. The requested output is concise, with file-and-line references in report.md. That scope makes the result more useful than an unrestricted request to find problems.

Runner compatibility determined the tool choice in this setup. The environment constraint was that Landlock was not enabled on the runner’s kernel, which broke Codex CLI’s sandboxing, while OpenCode ran in Docker with limited sandboxing on the same runner.

The trust boundary also remains explicit. Code passes through CI runners and to the model API, but the pattern does not grant another SaaS vendor persistent OAuth access to the repository. Long-running CI should favour direct API keys with a plan for rotating them.

Running Codex headlessly at scale: worktrees, parallelism, and the Cloud environment

Codex uses Git worktrees to give parallel tasks separate working copies of the same repository. That separation prevents jobs from editing the same working directory. It does not make their intended changes independent, however. Tasks that need to negotiate a shared interface still require coordination through CI and a human integrator.

The documented case of running at scale used a 200-word prompt that told an agent to watch CI, reproduce failures, suggest fixes, and open pull requests. Over six weeks, the workflow produced a high volume of pull requests each week. Subagents handled difficult failures while the main thread triaged work and messaged owners.

Codex Cloud runs tasks in an environment it manages. It clones the repository at submission, makes changes, runs tests, and creates a pull request. Setup has internet access to install dependencies, but the agent phase has no outbound internet access. GitLab support entered beta on August 19, 2026, so teams should treat this new integration as one that may still have rough edges.

Reliable tests become more important as these jobs multiply. Flakes can mislead an agent about whether its changes worked. They should be quarantined before agents get more freedom to act, because running more jobs in parallel will not overcome that noise.

Integrating headless agents with Slack, Linear, and GitHub so work starts where it already lives

Event-driven execution lets engineers hand off work from the tools that already have the task context. A GitHub issue can lead an agent through codebase exploration, planning, implementation, test updates, test execution, and a pull request. The developer still reviews and merges the result.

OpenAI publishes the Codex GitHub Action as openai/codex-action@v1. OpenCode’s current GitHub path uses custom workflow YAML, while mentioning @opencode in a GitLab comment triggers execution in GitLab CI. The community-maintained nagyv/gitlab-opencode component offers a minimal setup for that integration.

Slack provides another entry point. Mentioning Codex in a thread supplies the thread as context and files the work as a cloud task, allowing a support-channel bug to become a branch. The OpenCode-in-Docker pattern can also serve a Slack bot that takes a read-only repository copy and posts its answer back to the thread. That version supports codebase questions without opening an IDE.

Linear Agent can write code using Claude Code and Codex, and a session can start when it is assigned an issue or gets a request in chat, comments, or Slack. Linear also offers triage that gathers evidence through Sentry or Datadog via MCP before attempting a fix. Its internal use resolved roughly 30% of incoming bug reports on the first pass in 2026.

Running these agents in isolated cloud VMs rather than on CI runners or developer laptops

Shared CI runners place credentials, repository access, and tool execution in an environment used by other jobs. A dedicated VM narrows that shared exposure. Laptop execution has a different weakness because work pauses when the machine sleeps, and visibility is limited to local logs.

Codex Cloud gives each task a dedicated VM and allows work to continue when the developer’s computer is off. Reusable environments can have dependencies pre-installed. For OpenCode, isolated cloud VMs extend the Docker-in-CI pattern without changing the basic headless invocation and permission model. The surrounding infrastructure changes while the assignment sent to the agent stays the same.

VM isolation also creates room for stronger governance. That includes audit logs, source-control-scoped credentials that do not persist after the workspace sleeps, and recordings that can be reviewed before a pull request is merged. These are capabilities the execution platform can provide. They should not be confused with protections automatically supplied by a CLI flag.

What to watch for as you scale: review cost, permission scope, and flaky infrastructure

After a successful rollout, human review can become the hidden cost of agent throughput. Teams should track review hours as well as task volume to measure net engineering time saved. Tasks that are clearly spelled out tend to need fewer changes at review, while vague assignments can take longer to review than it would take to write the code by hand.

Permission scope can also grow bit by bit as teams add things the agent can do. Each expansion should be a deliberate policy decision. A workflow that began as read-only review has a different risk profile once it can implement changes or reach deployment systems.

Finally, greater concurrency amplifies weaknesses in task definition and infrastructure. Flaky tests make generated changes harder to trust, while overlapping assignments leave reviewers reconciling incompatible intent. The next increase in throughput therefore depends on independent tasks with measurable acceptance criteria.

Get a second opinion on your shortlist

Tell us what you're weighing and an engineer from the Replicas team, who operate this site, will reply by email. We'll point you to whichever option fits, including when that isn't Replicas.

Keep reading