Docs/CLI Reference
#

CLI Reference

All commands are under cofactor sandbox, and every sandbox belongs to an application (--application <name|id>). --env is the CLI's global flag for which Cofactor stage to talk to (dev / prod) — it has nothing to do with a sandbox's environment, which is always --environment.

bash
cofactor sandbox validate [file] [--upload]
bash
cofactor sandbox validate [file] [--upload] [--repo owner/name]

Offline schema + cross-check of a cofactor.sandbox.yaml. Defaults to the definition in the current directory if file is omitted. --upload checks a definition for pushed images (no setup); without it, one built from a GitHub checkout. The definition repository is the checkout's origin.

Pass --repo owner/name for a checkout without a GitHub remote (a CI mirror, an SSH host alias).

See the verify topic for the issue format.

An emulation plugin this CLI doesn't know but Cofactor lists (it shipped after your CLI) isn't an error: validate prints a note that its config is checked when the definition is uploaded or connected. Run cofactor upgrade to check it locally.

bash
cofactor sandbox emulators [id] [--json]

The emulators Cofactor offers, as served by the API (no sign-in needed; the copy bundled in this CLI if the API is unreachable). Without an id: each emulator's id and summary. With an id: its summary, docs link, domains, config keys (required ones marked) and operations. --json prints the registry entries, with the full JSON Schema of the config and of each operation's input and output.

bash
cofactor sandbox connect --application A --repo owner/name [--dir D]

Builds the application's sandboxes from a GitHub repository: the cofactor.sandbox.yaml under --dir (default: the repo root) at each commit. Its environments become the application's sandbox environments and its personas the application's personas. A new application name creates the application, with its sandbox default environment as its default environment; there is no base URL to give. It is created only after GitHub is connected (cofactor github connect), the repository is reachable and its definition is valid, so a refusal creates nothing. Without a pinned commit, connect reads the definition at the default branch's head; that version must hold a valid cofactor.sandbox.yaml. The selected definition supplies environments and personas. Later definitions add more when connected or refreshed; none is ever removed.

bash
cofactor sandbox connect --application A --repo owner/name [--dir D] --at <sha>

Reads the definition at that full pushed commit SHA, on any branch. No merge is needed, even if the default branch has no definition yet. The response describes the selected version; added environments and personas are retained if the branch is abandoned. An unknown commit says to push it first; a missing definition names the path and commit problem.

bash
cofactor sandbox push --application A [--context D] [--file F] [--target S] [--build-arg K=V]... [--definition F] [--tag T]... [--wait]
cofactor sandbox push --application A <image> [--definition F] [--tag T]... [--wait]

For an application that gives Cofactor no repository access: pushes an image (with its cofactor.sandbox.yaml) as the application's next version. Without an image, Cofactor builds the Dockerfile in --context (default .) for linux/amd64 and prints the build log; no Docker is needed. With an image, it pushes that local linux/amd64 image. A new application name creates the application, as connect does. See the upload topic.

bash
cofactor sandbox envs --application A [--json]

The application's delivery (GitHub or pushed images), its current version, each environment's head (see refresh), recent pushes, sandbox environments, and what its definition offers: every environment (descriptions, seeds), ports, personas, actions and emulator operations (with their schemas). This is what an agent reads to decide which environment to claim and how to call each action once it has a sandbox.

bash
cofactor sandbox refresh --application A [--environment E] [--wait]

Moves an environment's head to now. The head is what flow runs, the flow designer, scheduled runs and unpinned claims use: for GitHub, the ready snapshot of the default branch; for pushes, the newest push. It is never built per commit and never follows the default branch on its own, so it is normally behind it. It moves in two ways only: the background refresh (every 6 hours, for environments in use) and this command, which builds the default branch's tip as of this moment and advances the head when its snapshot is ready. A pushed application's head is already its newest push ("already at head <push id>"). Prints the old head, the new head and its build status; --wait blocks until the snapshot is ready or failed. A refresh while that snapshot is already building joins the build. Whoever can claim can refresh. envs shows each head and whether the default branch has moved past it, for information only.

For a GitHub application with repos, the default version includes the default-branch head of the definition repository and every member. Connect, refresh and the scheduled refresh follow the definition repository's default branch; refreshing it also updates the application's available member list. A change to a member's default branch changes the next default version, but does not itself refresh the definition or remove members.

bash
cofactor sandbox claim --application A [--environment E] [--at V] [--wait]

Claims a sandbox: a fresh copy of the ready snapshot for the version and environment (built first — build, prepare, seeds — if it doesn't exist yet), given its own URLs and logins by prepare. A version is a commit SHA for a GitHub-delivered application, or a push id or tag for a pushed one. A commit may be on any branch you pushed (it need not be merged), and is built with the definition in that commit. Without --at: the environment's head (see refresh); for GitHub, the default branch snapshot, else the default branch's tip if the head is stale; for pushes, the newest push. --environment defaults to default. --wait blocks until the sandbox is ready (or failed) instead of returning immediately with a claim id you'd otherwise have to poll with show.

For GitHub, each claim uses a revision: one immutable version of the definition and all its declared repositories. --at <sha> pins the definition repository to that commit and uses each member's default-branch head. Add repeatable --at <repo>=<sha> values to pin members too; <repo> may be a member name or full owner/name. For example:

bash
cofactor sandbox claim --org Acme --application A --at <definition-sha> --at api=<api-sha> --wait

Unpinned members use their default-branch heads. --at rev-<id> selects an exact revision with all repository commits fixed. A GitHub revision ID is shown as rev- followed by its digest; the revision and each repository's short commit are shown in claim details. Pushed-image versions and tags keep their existing meaning and cannot be combined with repository pins. --at rev-<id> cannot be combined with any other --at value.

bash
cofactor sandbox claim --application A --from-local [--repo owner/name] [--dir D] [--environment E] [--wait]

Sets up and claims the local files without a user commit or merge. The CLI snapshots the whole Git working tree (tracked files, tracked deletions, and nonignored untracked files), using a temporary index. It leaves your index, HEAD and branches alone. It pushes a deterministic commit object to refs/cofactor/wip/<tree-hash> with your own Git credentials, connects the application at that SHA, and claims it. --repo defaults to the origin push repository; --dir is relative to the repository root and defaults to the current directory. New application names work as with connect. --from-local and --at are mutually exclusive. The full source SHA is printed (the version field with --json); keep it for verify-env or a pinned suite. Unchanged files reuse the same SHA.

Inclusion follows Git: an unignored untracked file is pushed too. Set ignore rules before claiming, and keep credentials out of tracked files. A tracked file that is now ignored and has local changes makes the claim refuse; commit, revert or untrack it first. Push protection or a Git credential failure stops the claim and reports the push error. The CLI deletes its wip refs on destroy, or reaps them after seven days on a later local claim for that application. Another live claim keeps its ref. Cleanup uses your Git credentials; remote refs changed by someone else are left intact. Re-run --from-local to publish an expired ref again before rebuilding a lost snapshot. Deleting a ref does not erase GitHub's object storage immediately.

Multi-repository applications: what --from-local does depends on the checkout. Run from the definition repository's checkout, it connects the application at the local commit (the local definition is validated and its environments and personas synced; --dir is honored) and claims that version; the other members use their default-branch heads. Run from a member's checkout, it pins only that repository to the local commit and does not reconnect the application or require a definition file in the member. A checkout that is neither is refused. --repo names the checkout's repository (owner/name) when origin is not a github.com URL. The source repository and full source SHA are printed. Without --wait, --json prints { id, version, sourceCommit: {repo, sha} } for the definition repository's checkout; a member pin has no version, only { id, sourceCommit }. For a waited claim, JSON includes the revision ID in version and all repository SHAs in repos; use that revision ID to reproduce the whole vector, or --at <repo>=<sha> to pin a repository explicitly. The other repositories are resolved once for the revision. Uploaded images do not accept repository pins.

bash
cofactor sandbox claims [--application A] [--json]

Lists the sandboxes you claimed that are still claiming or ready: id, application, environment, status, when claimed and when the lease ends. Use it to find an id you lost, then destroy it.

bash
cofactor sandbox show <id>

Current status, per-port URLs, persona logins (decrypted — this is where they're meant to be read from, never a PR comment), the snapshot's seed steps with the time each took, seed outputs, and the available actions and operations.

bash
cofactor sandbox run <id> <action|plugin.op> [--input k=v ...] [--json-input '{...}']

Runs a definition action, an emulator operation (named <plugin>.<op>, e.g. email.sent-emails) or, when the definition declares databases, the built-in database.fast-forward (--input database=<name>; see the data-fast-forward topic) against a claimed sandbox, waits for it, and prints its output. --input is repeatable and coerced to the action/ operation's declared type (string/number/integer/boolean/persona); --json-input passes the whole input as JSON, overriding --input. Invalid input prints the action or operation's input schema instead of running it, so you can see what's expected.

bash
cofactor sandbox exec <id> [--timeout S] [--json] -- <command...>

Runs one shell command in a claimed sandbox, waits for it, and prints its output. One-shot: there is no interactive shell. It runs as the sandbox user in the definition's directory, with the environment actions get (the application's secrets included). Everything after -- is the command, its words joined with single spaces (ssh semantics), so quote pipes and redirects yourself: -- 'ls | wc -l'.

  • Output is the last 4000 characters of stdout and of stderr, scrubbed of the sandbox's secrets and persona logins (best effort: an encoded value isn't caught). The CLI exits with the command's exit code (124 on a timeout). A failure that isn't the command's (the helper, or a sandbox that can't exec) prints Error: ... and exits 1. --json prints the whole run instead.
  • --timeout S is 1 to 1800 seconds (default 300). On a timeout the command's whole process group is killed. Background processes (cmd &) keep running after a normal exit; redirect their output (cmd > log 2>&1 &), because the exec's pipes close when it returns. If the CLI stops waiting (its deadline is the timeout plus 60 s), the command may still be running in the sandbox.
  • Permissions: a signed-in CLI session (cofactor login) isn't scope-checked, so every org member can exec, just as they can run actions. An API key needs the sandbox:exec scope explicitly: sandbox:* does not include it, full access (*) does. Create a key with sandbox:exec selected under Sandboxes in Settings -> API keys (or POST /settings/api-keys with "scopes": [..., "sandbox:exec"]). Existing sandbox:* keys don't gain it, and a key's scopes can't be edited, so mint a new key.
  • Commands and their scrubbed output are visible in the sandbox's run history to anyone with sandbox:read. Don't type credentials into a command; set them as secrets (see the secrets topic).
  • Every exec is audited in the organization's events: who ran it (and with which API key), the sandbox, the scrubbed command, and how it ended (exit code, or a failure). Never its output. An exec that cannot be audited does not run.
  • Platform: works on sandboxes built on a platform that has exec. An older sandbox answers "This sandbox was built on an older platform; exec works once it is rebuilt on a newer one." Exec ships with the next sandbox platform update (it needs no bump of its own).
bash
cofactor sandbox sync <id> [--build] [--json]
cofactor sandbox sync <id> <local-dir> --to <path> [--json]
bash
cofactor sandbox sync <id> [--build] [--repo owner/name] [--json]

Makes a sandbox you claimed match your working tree, uncommitted and untracked changes included, straight over the sandbox's own sync port. It lists every file it writes (untracked ones marked) and deletes, then applies, records the synced tree id (show prints it) and extends the sandbox's lease (up to 8 h after the claim).

--repo owner/name names the checkout's repository when its origin is not a github.com URL.

Nothing restarts on its own: exec <id> -- cofactor-sandbox restart <service>. --build reruns the definition's changed build steps and restarts after_build services (GitHub and pushed applications alike). --to mirrors local build output into <path>. Needs the same sandbox:exec scope as exec. See the local topic.

bash
cofactor workflow run <flow> --sandbox <id>

Runs a flow on a sandbox you claimed instead of a fresh copy, and never destroys it. The run targets the sandbox's own application and environment. An --environment of another application or sandbox environment is refused. The run records the version and synced tree (cofactor workflow debug overview <run>). An API key also needs sandbox:read.

bash
cofactor sandbox destroy <id>

Tears the sandbox down. Always do this when a claimed sandbox is no longer needed — it isn't reclaimed automatically mid-session.

bash
cofactor sandbox secret set <NAME> --application A [--environment E] [--json]

Stores a third-party secret (an API key) for the application, for every environment, or for just --environment E (an override). The value is read from stdin only and the CLI refuses a terminal: printf %s "$KEY" | cofactor sandbox secret set NAME --application A. One trailing newline is stripped. A name is an environment variable name (capital letters, digits and _, not starting with a digit; not PATH, HOME, USER, SHELL, NODE_OPTIONS, NODE_EXTRA_CA_CERTS, LD_* or COFACTOR_*); a value is 8 to 8192 bytes, with no NUL. Fast copies of an existing ready snapshot keep its old value until a new commit or image push rebuilds the snapshot. Legacy-prepare claims see the change on the next claim. Prints Secret NAME set for all environments of A. (or ... for environment "E" of A.). See the secrets topic.

bash
cofactor sandbox secret list --application A [--json]

Names and scopes (all environments, or one) with the time last set. Never values. With none set it prints No secrets set for A.

bash
cofactor sandbox secret rm <NAME> --application A [--environment E] [--json]

Removes the secret at that scope: without --environment, the application-wide one; with it, that environment's override. Prints Secret NAME removed for all environments of A. (or ... for environment "E" of A.). A secret that is not set fails with "No secret with that name and scope.". Fast copies of an existing ready snapshot keep the removed value until a new commit or image push rebuilds the snapshot. Legacy-prepare claims see the removal on the next claim. See the secrets topic.

bash
cofactor sandbox verify-env --application A [--environment E]

Claim → wait → report seed outputs and timings → sign every persona in (when the definition declares authentication) → destroy, for each environment of the current version (or the one named). The end-to-end proof that an environment's seed chain and persona logins actually work, not just that they're well-formed. Without a pinned version it verifies the application's default version. See the verify topic.

bash
cofactor sandbox verify-env --application A --at <sha> [--environment E]

Verifies that pushed commit's own definition, environments and personas before any merge. Use the source SHA from claim --from-local for the same check without making a user commit.

For a multi-repository application, --at <sha> takes the definition repository's full commit SHA; the other members are at their default heads. To check a claimed multi-repository revision, claim it with --at rev-... (or --at <repo>=<sha> pins) and run auth-check or exec against that sandbox; verify-env does not accept a rev-... id. A member checkout's source SHA belongs to that member alone, so it is not a valid --at here.

bash
cofactor sandbox auth-check <id> --persona <name> [--json]

Signs one persona in on an existing claim as a Login step would, prints pass/fail, and exits nonzero if sign-in fails. It returns no session state.

bash
cofactor sandbox preview --application A --pr N
bash
cofactor sandbox preview --application A --pr N [--repo owner/name|name]

A pull request's preview of a GitHub-delivered application: status, URLs, the logins GitHub deliberately never sees, and the URL of its Cofactor page (the same details plus build output on failure, for signed-in org members). The PR's GitHub deployment links that page as its "View details".

A pull request in a member repository also gets a preview. When its head changes, the preview captures that commit plus the other repositories' default-branch heads. Later changes to another member alone do not rebuild the open preview. If the same pull request number exists in more than one repository, pass --repo to choose which preview to show.

To run a test on it (a private copy at its applied head, never the shared preview):

bash
cofactor workflow run <workflowId> --preview N --application A
bash
cofactor workflow run <workflowId> --preview N --application A --repo owner/name|name

and to list tests in a pull request as proof: cofactor proofs guide.

bash
cofactor sandbox guide [topic]

Prints this guide (guide v2 [topic] is the same). Omit topic to print every section; name one (e.g. upload) to print just that topic. guide v1 [section] prints the guide for the earlier sandboxes (its verify section is guide v1 verify; plain guide verify is this guide's).

The core loop

validate → (connect | push) → envs → claim --wait → run (actions/ operations, as many as the test needs) → destroy. Always validate a changed definition before pushing it — see the verify topic for why. A GitHub-delivered application is never tried in local Docker (see overview).

Setting up a new GitHub application

Plan first (plan): nothing below runs until the human has approved the plan.

Never build or run the GitHub app in local Docker or a local container. Validate locally; build and prove it with a Cofactor claim. Use CLI 0.56.0 or later for the following no-merge setup commands; upgrade an older CLI instead of merging an unproved definition to unlock setup.

  1. Write cofactor.sandbox.yaml and run cofactor sandbox validate until clean. Review Git's ignored and untracked files before sending them. Keep third-party credentials in the application's secret store, never in the definition or local files sent to Git.

  2. Choose the source:

    • Already pushed on a branch: use its full commit SHA, with the definition and scripts in that commit:

      bash
      cofactor sandbox connect --application A --repo owner/name --at <branch-sha>
      cofactor sandbox claim --application A --at <branch-sha> --wait
      

      Add --dir D to connect for a monorepo definition directory.

    • Local files, including a new uncommitted definition:

      bash
      cofactor sandbox claim --application A --from-local --wait
      

      This also connects the application. No user commit, branch push or merge is needed. Use --dir D from the repository root for a monorepo; --repo owner/name overrides origin's inferred GitHub name.

    For an existing application, set its required test secrets before the first claim (see secrets). If a new application is created and its first claim reports a missing secret, set that secret and retry with the same application name. Connect retains added environment and persona names; abandoning the branch does not prune them.

  3. Iterate on that copy:

    bash
    cofactor sandbox sync <id> --build
    

    This adopts changed lifecycle.build steps, services and env, and restarts the affected services (see local). Existing action script files and authentication.run scripts also apply after a plain sync. Data and applied migrations stay. Changes to setup, resources, ports, prepare, seeds, personas, actions or other nonsyncable definition fields need a fresh snapshot: validate, then claim again with --from-local, or use a newly pushed branch SHA. A failed claim has no running copy to sync; fix the files and claim again by the same path. Use --from-local for retries without a user commit or merge.

  4. Prove a fresh source snapshot, rather than just a synced copy. After the last edit, validate and claim --from-local again (or claim the final pushed SHA). Record its full source SHA, then:

    bash
    cofactor sandbox verify-env --application A --at <source-sha>
    

    For a multi-repository application, verify-env --at takes only the definition repository's full commit SHA (other members at their default heads). To check a claimed multi-repository revision, claim it with --at rev-... (or --at <repo>=<sha> pins) and run auth-check or exec against that sandbox.

    This checks each environment and signs every declared native persona in. Open the claimed copy's web URL too and confirm the app renders and each role lands where it should. For a focused sign-in check:

    bash
    cofactor sandbox auth-check <id> --persona <name>
    

    A workflow can run before merge:

    bash
    cofactor workflow run <flow> --sandbox <id>
    

    A suite can pin the same SHA with cofactor test-suite run --at. Destroy your claims when finished. Merge only when the user wants the proven definition and code adopted on the default branch. At that point commit and push the files for review, and prove that final SHA if it differs; after merge, refresh --wait and unpinned verify-env check default-branch adoption. They are not prerequisites to setup.