Run Droid Exec and the Droid SDK in CI and locked-down environments
Install a pinned Droid CLI and SDK without public registry access, then run headless jobs with a Factory API key and no interactive login.
This page shows how to run droid exec and the Droid SDKs on a CI runner, or on any machine that can't reach public package registries. You install exact versions from a registry you control, keep them at those versions, authenticate with an API key, and keep the job away from the runner user's own Droid settings.
The examples ran on Linux x64 with npm 11.20.0, Droid CLI 1.20.0, TypeScript SDK @factory/droid-sdk 0.11.0, and Python SDK droid-sdk 0.5.0. npm could reach only the mirror; pip used a local wheelhouse with networking disabled. The successful prompts ran in a separate step with network access to Factory.
What you need
- An npm-compatible registry you control that can serve the packages listed in Mirror the packages.
- Node.js 22.23.4 to reproduce the TypeScript example without a build step. The CLI's npm package declares Node.js 20 or later; the SDK alone declares 18 or later.
- For the Python SDK: a wheelhouse (a directory of approved wheels). The SDK declares Python 3.10 or later; the example ran on 3.12.3.
- A glibc-based Linux x64 image for these examples. The tested native binary uses the loader
/lib64/ld-linux-x86-64.so.2. - A Factory API key, stored in your CI system's secret store.
- Outbound HTTPS from the job to Factory when the job runs a prompt. Installing packages needs only your registry. See Network access.
Mirror the packages
The CLI ships on npm as a small wrapper plus platform-specific native packages. The wrapper gets the binary through optional dependencies, so your mirror has to carry the wrapper and the native packages for your runners at the same version.
| Package | What it provides |
|---|---|
@factory/cli | The wrapper that provides the droid command. The examples on this page use it. |
droid | An alias of @factory/cli that also provides the droid command. Install one of the two, not both. |
@factory/cli-<os>-<arch> | The native binary. There are nine: <os> is linux, darwin or win32, and <arch> is arm64, x64 or x64-baseline. The x64-baseline builds are for older x64 CPUs without AVX2. |
@factory/droid-sdk and its dependencies | The TypeScript SDK. It does not include the CLI. |
droid-sdk and its dependencies, as wheels | The Python SDK. It does not include the CLI. |
Serve the package metadata for all nine native packages, even if you only serve the binaries your runners use. npm 11.20.0 wrote all nine entries into the working package-lock.json. When the mirror served metadata only for the two Linux x64 packages, npm install succeeded, but npm ci rejected the lockfile it had written:
npm error code EUSAGE
npm error
npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
npm error
npm error Missing: @factory/cli-darwin-arm64@ from lock file
npm error Missing: @factory/cli-darwin-x64@ from lock file
npm error Missing: @factory/cli-darwin-x64-baseline@ from lock file
npm error Missing: @factory/cli-linux-arm64@ from lock file
npm error Missing: @factory/cli-win32-arm64@ from lock file
npm error Missing: @factory/cli-win32-x64@ from lock file
npm error Missing: @factory/cli-win32-x64-baseline@ from lock fileWith metadata for all nine, the same steps produced a lockfile that npm ci accepted, and the Linux x64 runner downloaded only the linux-x64 and linux-x64-baseline binaries.
Install exact versions
Commit a package.json and package-lock.json that pin the CLI and, if you use it, the TypeScript SDK. Then install from the lockfile in every job.
- 1Create the lockfile once
In a project whose
package.jsonis{"private":true}, run this against your registry. Replacehttps://npm.example.internal/with your mirror's URL.Bashnpm install --registry=https://npm.example.internal/ --save-exact --include=optional \ --no-audit --no-fund --ignore-scripts @factory/cli@1.20.0 @factory/droid-sdk@0.11.0--save-exactrecords the exact versions, sopackage.jsonreads"@factory/cli": "1.20.0"and"@factory/droid-sdk": "0.11.0"rather than a range. Leave out@factory/droid-sdk@0.11.0if the job only runsdroid exec. Check theresolvedtarball URLs inpackage-lock.jsonbefore committing both files. The test mirror served the tarballs itself, so every URL pointed back to it. - 2Install from the lockfile in CIBash
npm ci --registry=https://npm.example.internal/ --include=optional --ignore-scripts --no-audit --no-fundWith a fresh npm cache and no network route except to the mirror, this printed
added 106 packagesfor the CLI and SDK oradded 3 packagesfor the CLI alone. Both exited0. - 3Check the executable, not only npm's exit statusBash
./node_modules/.bin/droid --versionThis prints
1.20.0. Run it as its own CI step, for the reason below.
Two flags matter for a locked-down install:
-
--include=optionaltells npm to include optional dependencies such as the native binary. It can't supply a package missing from the mirror. -
--ignore-scriptskeeps the wrapper's install script from running. In1.20.0, when that script can't find the native package, it tries to download it from the public npm registry, outside your mirror. With the binary missing and scripts enabled, the install printed:Platform-specific binary not found in optionalDependencies. Downloading @factory/cli-linux-x64@1.20.0 from npm... Failed to download binary: getaddrinfo EAI_AGAIN registry.npmjs.org The "droid" command will use the JavaScript fallback. For better performance, ensure optionalDependencies are installed.With
--ignore-scripts, that script didn't run, anddroid --versionstill printed1.20.0when the native package was present.
A missing native package does not fail the install. With or without install scripts, npm install exited 0, and the first droid command failed with exit code 1:
Error: Could not find the droid binary for linux-x64.
This usually means the optional dependency "@factory/cli-linux-x64" was not installed.
Try running: npm install
If you're using npm with --ignore-scripts, the binary may not have been set up correctly.In this check, the mirror was missing the native package. Check that your registry serves it and that the install includes optional dependencies. Keep the version check even if npm reports success.
Keep the CLI at the pinned version
The npm build of the CLI ships with automatic updates turned off. Set FACTORY_DROID_AUTO_UPDATE_ENABLED=false (or 0) in the job's environment to make that choice explicit. The manual droid update command honors it too:
FACTORY_DROID_AUTO_UPDATE_ENABLED=false ./node_modules/.bin/droid updateAuto-update is disabled by environment or build configuration.
For npm installations, run: npm update -g @factory/cliThe command exited 0 without replacing the binary. Its SHA-256 checksum was the same before and after. The second line is part of the CLI's message, not a step for a pinned job.
Don't set the variable to true or 1 in a pinned job. With either value, droid update --check checked for updates; with the variable unset, this npm build reported that updates were disabled. To change the pin, repeat the lockfile step with the version you want. See auto-updates in the CLI reference.
Authenticate with an API key
Store a Factory API key as a masked secret in your CI system, and expose it to the step that runs Droid as the environment variable FACTORY_API_KEY. The CLI and both SDKs read it from there. The job needs no browser, interactive login or preconfigured user settings file. droid exec --help links to the API keys settings page.
Keep the key out of prompts, command-line arguments, source files and build output.
The checks on this page used a personal API key. They have not been repeated with a service account key.
When the key is missing or wrong, the run fails. These are the results the checks recorded, with Factory-managed models:
| Situation | droid exec -o json | TypeScript run() | Python run() |
|---|---|---|---|
FACTORY_API_KEY not set | Exits 1 with "subtype":"failure", "num_turns":0, and the result Authentication failed. Please log in using /login or set a valid FACTORY_API_KEY environment variable. | Throws No Factory API key found. Pass `apiKey` when creating the session, or set the FACTORY_API_KEY environment variable. | Returns an unsuccessful result whose error message is No access token available. |
FACTORY_API_KEY set to an invalid value | Exits 1 with "num_turns":0 and the result Authentication failed. FACTORY_API_KEY is set but appears to be invalid. Unset it or replace it with a valid key. | Returns an unsuccessful result whose error message starts with 401 and contains Access token is invalid or expired. Please sign in again. | Same as TypeScript. |
Run droid exec
Pass the prompt as an argument. droid exec runs it without any interactive input and exits. This prompt makes a useful smoke test for the first step of a job, because it checks the install and the key together:
./node_modules/.bin/droid exec -o json \
'Do not use tools or change anything. Reply exactly CI_OK.'This smoke test needs no --auto flag. It ran at the default, which droid exec --help describes as read-only. Choose an autonomy level only if the task needs more permissions. Don't rely on --auto medium to prevent pushes: in a separate check it allowed a non-force git push to a local bare repository.
The JSON result arrives as one line. It's formatted here for reading:
{
"type": "result",
"subtype": "success",
"is_error": false,
"duration_ms": 3561,
"num_turns": 1,
"result": "CI_OK",
"session_id": "c57e6c7b-90e0-4dbc-84a0-f8adf5d88306",
"usage": {
"input_tokens": 4,
"output_tokens": 7,
"cache_read_input_tokens": 10071,
"cache_creation_input_tokens": 7844,
"factory_credits": 16557,
"thinking_tokens": 0,
"ttft_ms": 1842
}
}The process exited 0. Without -o json, the same prompt printed only the reply, CI_OK. The failed authentication runs exited 1 and reported "is_error": true.
Exit code 0 means the run completed. It does not mean the task succeeded, so check the work with your own tools. See exit behavior.
Use the TypeScript SDK
@factory/droid-sdk has no install script and does not depend on the CLI. It starts a local droid exec process, using the droid on PATH unless you pass execPath. If you used the lockfile above, both are already installed.
import { run } from "@factory/droid-sdk/node";
const result = await run("Do not use tools or change anything. Reply exactly TS_PIN_OK.", {
execPath: process.argv[2],
});
if (!result.success) throw new Error(result.error?.message ?? result.subtype);
console.log(result.text);node pinned.mts ./node_modules/.bin/droidThis printed TS_PIN_OK and exited 0 on Node.js 22.23.4, with no droid on PATH and no build step. When droid is on PATH, you can leave out execPath. With neither, the run fails to start:
Failed to start Droid: executable not found (droid)Check result.success yourself. An invalid key comes back as an unsuccessful result, not as an exception, so a script that only catches exceptions would not notice the failure.
Use the Python SDK
droid-sdk does not include the CLI. Install the CLI from your npm mirror as shown above, and the SDK from your wheelhouse. Replace /path/to/wheelhouse with yours; it needs wheels for droid-sdk and its dependencies for your Python version and platform.
python3 -m venv .venv
.venv/bin/python -m pip --isolated --disable-pip-version-check --no-cache-dir install \
--no-index --find-links=/path/to/wheelhouse droid-sdk==0.5.0Successfully installed annotated-types-0.8.0 droid-sdk-0.5.0 pydantic-2.14.4 pydantic-core-2.50.5 typing-extensions-4.16.0 typing-inspection-0.4.5The SDK starts droid from PATH unless you pass Runtime(executable=...):
import asyncio
import sys
from droid_sdk import Runtime, run
result = asyncio.run(run("Do not use tools or change anything. Reply exactly PY_PIN_OK.",
runtime=Runtime(executable=sys.argv[1])))
if not result.success:
raise SystemExit(result.error.message if result.error else result.subtype)
print(result.text).venv/bin/python pinned.py ./node_modules/.bin/droidThis printed PY_PIN_OK and exited 0 with no droid on PATH. With neither PATH nor executable, the run raises:
droid_sdk.errors.DroidConnectionError: Droid executable was not found, cwd='...'Check result.success. In Python, a missing key and an invalid key both return an unsuccessful result instead of raising. In TypeScript, only an invalid key does; a missing key throws.
Neither pinned SDK installed a missing CLI. Give it a droid on PATH or an explicit path. Each local SDK example started a droid exec subprocess; the job didn't need to start a daemon.
Keep the job's settings separate from the runner's
Droid reads its user settings from $HOME/.factory/settings.json. On a runner that is shared, or that a person also uses, give each job its own empty HOME:
HOME=/ci/job-home ./node_modules/.bin/droid exec \
'Do not use tools or change anything. Reply exactly HOME_OK.'The run printed HOME_OK. When we watched the user settings files, it opened the one under the job's HOME. A run in a fresh home also wrote its sessions and cache there.
Changing the user settings directory does not isolate the session. The run also opened the project's .factory/settings.json. Use a checkout you trust as well as a clean home. The checks cleared inherited FACTORY_ variables before supplying the job's settings and key. For runner isolation, see secure containers and VMs.
Network access
Installation from the test mirror needed no other network access. Running the same Factory-managed prompt with no network route returned Connection error. and exited 1; with access to Factory it returned CI_OK and exited 0. Use the outbound network allowlist to plan runtime access separately from package installation.
We didn't measure the host list for custom models or run through a proxy. See custom models (BYOK), proxies, custom CAs and mTLS, or airgapped deployment for those configurations.
Limits of these examples
- Privacy. These jobs don't set a privacy level or establish that only usage counts leave the runner. See telemetry privacy controls and session contents sync.
- Model gateways. These SDK examples use Factory-managed models, not a per-session gateway. See custom models (BYOK) for a different setup.
- Settings. A clean home does not suppress project settings. See Keep the job's settings separate from the runner's.
- Local SDK sessions. These versions ran a separately installed CLI, not a shared daemon.
Not covered yet
The checks behind this page did not include these. Treat them as untested here, even where other pages document them:
- Service account API keys.
- Runners other than Linux x64, including arm64, macOS and Windows.
- GitHub Actions, GitLab CI or Jenkins pipeline files. The commands above were run in a Linux shell, not in those CI systems.
- Yarn, pnpm, and the standalone (non-npm) installers.
- Custom models (BYOK) on a locked-down runner, including how a misconfigured custom model fails.
- A measured list of the hosts a single run contacts.
- HTTP proxies, custom certificate authorities and mTLS.