droid exec: Run Factory Droid Headless in CI (2026 Guide)

TL;DR
A practical guide to droid exec, the headless mode of Factory Droid: autonomy levels, output formats, tool controls, worktrees, GitHub Actions, PR review with droid-action, and the safety traps to avoid.
Last updated: November 26, 2026
droid exec is the part of Factory Droid that runs without you. It takes one prompt, does one pass, writes to stdout and exits, which is what you need for CI jobs, cron, git hooks and batch refactors. Every flag and example below comes from Factory's Droid Exec docs and CLI reference as of CLI v1.21.0 (November 25, 2026). Where an example is adapted, it says so. We did not run these against a live Factory account while writing, so treat them as documented behavior and test them on a throwaway branch first.
If you have used codex exec or Claude Code's print mode, the shape is familiar. Our codex exec CI guide and the headless agents in CI comparison cover the alternatives.
Install and authenticate#
The CLI ships through four channels:
# macOS / Linux
curl -fsSL https://app.factory.ai/cli | sh
# Homebrew
brew install --cask droid
# npm
npm install -g droid
On Windows, Factory documents irm https://app.factory.ai/cli/windows | iex.
For headless use you do not log in. Generate a key on the Factory API keys page and export it:
export FACTORY_API_KEY=fk-...
One container gotcha worth knowing before you write a Dockerfile: the Droid CLI needs a glibc-based Linux image such as Debian or Ubuntu. It does not run on Alpine.
The execution model#
Each droid exec call is a single pass. By default it is read-only: Droid can read files and run read-only commands such as git status, git log and git diff, but cannot edit anything. That default is the most important design decision in the tool, because it means a forgotten flag fails safe.
You can pass the prompt four ways:
droid exec "analyze code quality" # inline
droid exec -f prompt.md # from a file
echo "summarize repo structure" | droid exec # from stdin
droid exec --session-id <id> "continue with next steps" # resume a session
The stdin form composes well with git. The CLI reference shows git diff | droid exec "draft release notes".
Autonomy levels#
Mutations are opt-in through --auto. Factory's table, condensed:
| Flag | Allows | Still blocked | Use for |
|---|---|---|---|
| (none) | Reads, listings, git read operations | Edits, installs, git writes | Analysis, reviews, reports |
--auto low | Low-risk file creation and edits | Installs, remote writes, system changes | Docs, comments, formatting |
--auto medium | Low plus installs, builds, tests, git commit, git push, gh pr create | Force pushes, sudo, production changes | Dependency updates, test fixes |
--auto high | Force pushes, deployments, migrations | Extreme destructive operations | Controlled CI/CD environments |
--skip-permissions-unsafe | Skips all permission prompts | Command blocks still apply | Throwaway containers only |
Two behaviors matter in CI. First, fail-fast: if Droid attempts an action above the current level, the run stops at that action, prints an error to stderr and exits non-zero. Edits made before that point stay in the working tree, so clean up before retrying at a higher level. Second, --skip-permissions-unsafe cannot be combined with --auto, and a permission rule that blocks a command still blocks it.
Factory's own best-practice list is conservative and worth adopting as-is: start read-only and redirect output to a file, use --auto low only when Droid must edit, and commit and push in your own script steps instead of giving Droid --auto medium. That keeps the agent's blast radius to the working tree and leaves git writes to code you control.
Preview your command policy#
Permission rules can allow, ask or block commands. A headless run cannot answer an ask, so an effective ask is not cleared by --auto high. Check what your rules will do before the job runs:
droid rules check
droid rules check --command 'git push origin main' --json
Factory warns that a successful check can still report block, so read the decision rather than treating exit code 0 as an allow.
Output formats#
Pick one with -o:
text(default) - the final response, good for logs and> report.mdjson- one object at the end withresult,session_idandusagestream-json- one event per line:system,message,tool_call,tool_result,completionstream-jsonrpc- the full JSON-RPC protocol for custom integrations
JSON is the one you want in scripts, because it hands you the session ID for a follow-up turn. Adapted from the docs:
out=$(droid exec -o json "Summarize this repository in one sentence")
echo "$out" | jq -r .result
droid exec -s "$(echo "$out" | jq -r .session_id)" "Now list its packages"
The usage block in that JSON includes a factory_credits field, which is how you attribute spend per job. Stream mode is useful for recording which tools a run used:
droid exec -o stream-json --auto medium "Fix the failing test" \
| jq -r 'select(.type == "tool_call") | .toolName'
Exit codes are not verdicts#
This is the trap that catches most first CI integrations. droid exec exits 0 when the run completes and non-zero when it stops early (a permission stop, a bad flag, an API error). In Factory's words, "Exit 0 means Droid finished, not that the task succeeded."
So every job that edits code needs a deterministic check after it. When you ask Droid for a structured artifact, validate it:
droid exec --auto low "Write deps.json: an array of {name, version, usedIn}
for each direct dependency"
jq -e 'type == "array"' deps.json
For code changes, the check is your test suite or type checker, run as a separate step that Droid does not control.
Models, reasoning and spec mode#
Choose a model with -m and reasoning effort with -r. Note that in droid exec, -r means --reasoning-effort, while in interactive droid it means --resume.
droid exec -m claude-opus-5-5 -r medium -f plan.md
--use-spec makes Droid plan before it acts, and --spec-model lets the planning phase use a different model than the execution phase. A strong planner with a cheaper executor is the obvious pattern:
droid exec --use-spec --spec-model claude-opus-5-5 --auto medium \
"implement feature X"
The model IDs and their usage multipliers are on the models page. Since every CI run draws from the same rate limits as your interactive sessions, the multiplier choice is a real budget decision; our Droid pricing explainer covers how that works. --model also accepts provider tier aliases such as openai-latest-balanced, which follow Factory's recommended model for that tier as new models ship. That is convenient, but it means a nightly job can change models without a commit, so pin an explicit ID where reproducibility matters.
Tool controls#
You can shrink the agent's toolset per run. List what is available first:
droid exec --list-tools
Then restrict:
# Read-only analysis with only the search tools
droid exec --only-tools Read,Grep,Glob,LS "Map the auth module"
# Allow edits but no shell commands
droid exec --auto low --remove-tools Execute "Add JSDoc to src/api"
# Add every tool from a configured MCP server
droid exec --add-tools MCP:linear "Summarize my open issues"
An unknown tool name fails the run before Droid starts, which is the behavior you want in CI. --remove-tools Execute combined with --auto low is a particularly useful pairing: Droid can edit files but cannot run anything, so a prompt injection in a file it reads has no shell to reach.
Parallel runs with worktrees#
-w, --worktree [name] runs a task in its own git worktree on its own branch, which is how you fan out without jobs overwriting each other. From the docs:
droid exec --worktree codemod-a --auto medium "apply codemod A" & a=$!
droid exec --worktree codemod-b --auto medium "apply codemod B" & b=$!
wait "$a"; status_a=$?
wait "$b"; status_b=$?
[ "$status_a" -eq 0 ] && [ "$status_b" -eq 0 ]
Clean worktrees are removed on exit and dirty ones are kept so you can review them. For per-file work, plain xargs -P with bounded concurrency is documented too:
find src -name '*.ts' -print0 | xargs -0 -P 4 -I {} \
droid exec --auto low "Refactor {} to use modern TypeScript patterns"
If you already run parallel agents with worktrees in other tools, our git worktrees for parallel agents guide covers the general pattern.
A GitHub Actions job#
Factory's docs include a weekly read-only analysis matrix. This is a trimmed version of that workflow:
name: Droid cleanup analysis
on:
schedule:
- cron: '0 1 * * 0'
workflow_dispatch:
permissions:
contents: read
jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
module: [components, services, utils, hooks]
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Install Droid CLI
run: |
curl -fsSL https://app.factory.ai/cli | sh
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
- name: Find dead code
env:
FACTORY_API_KEY: ${{ secrets.FACTORY_API_KEY }}
MODULE: ${{ matrix.module }}
run: |
droid exec --cwd "$GITHUB_WORKSPACE/src/$MODULE" \
"Find unused exports, dead code, and deprecated patterns.
Respond with a Markdown list of cleanup recommendations." \
> cleanup-report.md
- uses: actions/upload-artifact@v7
with:
name: cleanup-${{ matrix.module }}
path: cleanup-report.md
Note what this job does not do: it never passes --auto, it checks out with persist-credentials: false, and the token is read-only. The output is an artifact for a human, not a commit. That is the right first rung. Once you trust the prompts, Factory publishes fuller recipes that edit code and open PRs: lint autofix, dependency and secret scanning and nightly docs and tests.
PR review without scripting it#
For pull request review, you do not need to wrap droid exec yourself. Factory ships Factory-AI/droid-action, which handles review, security review and PR description fill. The quickest setup is to run droid and type /install-code-review. The minimal workflow from the Automated Code Review docs looks like this:
name: Droid Auto Review
on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
review:
if: ${{ !github.event.pull_request.draft }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
checks: write
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: Factory-AI/droid-action@main
with:
factory_api_key: ${{ secrets.FACTORY_API_KEY }}
automatic_review: 'true'
The docs reference the action at @main. For a production repo, pin it to a release tag or commit SHA so an upstream change cannot alter what runs against your code.
The hooks trap in untrusted repos#
This one is easy to miss. Interactive droid asks you to trust a folder; droid exec does not, and an untrusted folder does not stop it from running the repository's project hooks or the hooks of plugins the project enables. If your CI runs droid exec on pull requests from forks, a malicious PR can ship a hook. Factory's documented fix is a per-run settings file:
settings="$(mktemp)" &&
echo '{"hooks": {"hooksDisabled": true}}' > "$settings" &&
droid exec --settings "$settings" "Summarize this repository"
A hooksDisabled: true in your user settings is not enough if the repo's project settings set it back to false, because project settings outrank user settings. Use --settings on every run against code you did not write. The broader version of this risk is covered in our agent security checklist.
Missions from the command line#
droid exec --mission runs a multi-agent orchestrator headless, with separate models for workers and validators. It requires --auto high or --skip-permissions-unsafe:
droid exec --mission \
--worker-model claude-opus-5-5 \
--validator-model gpt-6.2-sol \
--auto high \
"ship the new billing webhook end-to-end"
That combination of high autonomy and long runtime is exactly where the guardrails above matter most. Missions also require Extra Usage on individual plans. Whether a Mission is the right tool at all is the subject of Droid Missions vs Workstreams vs custom droids.
A sensible rollout#
- Week one: read-only reports. No
--auto, output to artifacts, a human reads them. - Week two:
--auto lowwith--remove-tools Execute. Droid edits, your pipeline runs the tests, your script commits. - Later:
--auto mediumin a worktree, only for jobs whose output is a PR that still needs human review. - Only in disposable runners:
--auto highor--skip-permissions-unsafe, never on a machine with production credentials.
Each step widens what the agent can do only after the previous step has a track record. That is slower than turning on high autonomy on day one, and it is the reason the rollout survives its first bad prompt.
FAQ#
What is droid exec?#
droid exec is the non-interactive mode of the Factory Droid CLI. It runs one task, writes to stdout and stderr, and exits, which makes it usable from shell scripts, cron jobs and CI pipelines. It is read-only unless you pass an --auto level.
How do I authenticate droid exec in CI?#
Generate an API key in Factory settings and expose it as the FACTORY_API_KEY environment variable, for example from a GitHub Actions secret. droid exec picks it up without an interactive login.
What do the --auto levels allow?#
With no flag, droid exec is read-only. --auto low allows low-risk file edits. --auto medium adds installs, builds, tests, git commit, push and gh pr create. --auto high adds force pushes, deployments and migrations. --skip-permissions-unsafe skips every prompt and belongs only in disposable environments.
Does exit code 0 mean the task succeeded?#
No. Factory documents that exit 0 means Droid finished, not that the task succeeded. Check the result with your own tests, linters or a jq assertion on an artifact before trusting it.
Is there an official GitHub Action for Droid?#
Yes. Factory-AI/droid-action handles pull request review, security review and PR description fill. You can set it up by running /install-code-review inside an interactive droid session.
Continue Reading#
- Set Up Factory Droid Properly
- Factory Droid: Review and Setup Guide
- Factory Droid Pricing Explained
- codex exec in CI: the headless guide
- Headless AI coding agents in CI compared
- All Droid guides
Sources#
- Droid Exec (Headless): docs.factory.com/droid-exec/overview
- Droid CLI reference: docs.factory.com/droid-cli/cli-reference
- CI and locked-down environments: docs.factory.com/droid-exec/ci-and-locked-down-environments
- Automated Code Review: docs.factory.com/automations/code-review-ci
- Permission rules: docs.factory.com/autonomy-and-safety/permission-rules
- Factory-AI/droid-action: github.com/Factory-AI/droid-action
- Release notes (CLI v1.21.0): docs.factory.com/changelog/release-notes
Get the next deep dive like this in your inbox
One email a week on Droid and the rest of the AI dev stack. Free.
Read next on AI coding tools
Factory Droid: Review and Setup Guide (2026)
Factory Droid review and setup: a terminal-native AI coding agent with multi-model routing, headless CI and browser automation, and if it fits your workflow.
8 min readFactory Droid Pricing Explained: Plans, Rate Limits and Multipliers (2026)
Droid pricing in plain terms: the free BYOK tier, Pro, Plus and Max, the three rolling rate limits, Droid Core, Extra Usage, and how model multipliers decide how fast your plan drains.
9 min readCodex Exec in CI: Practical Guide to Headless OpenAI Agents
codex exec is OpenAI's non-interactive mode to run Codex agents from scripts, CI and GitHub Actions. How to set it up safely with real flags and working YAML.
9 min readNew here? Start with
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.





