Build from a pushed image
Build your app's image in your own CI and push it to Cofactor with no repository access, then push a fresh one every night.
You push your app to Cofactor with its cofactor.sandbox.yaml: either the Dockerfile and its build context, which Cofactor builds for you, or an image you built yourself. Each push becomes a version that anyone can claim as a live copy (a sandbox, also called a test environment).
Use this page if you can't connect GitHub. An application takes pushed images or a GitHub repository. The first push makes it a pushed-image application. The examples use an invented app, Project Tracker, served on port 8080.
Push your first image
-
Choose or write a Dockerfile. Cofactor builds it for you, so you don't need Docker. Pick one:
- The app's own Dockerfile, if it meets the image rules below.
- A new Dockerfile, if the app has none.
- A separate sandbox Dockerfile, such as
sandbox/Dockerfile, when the production one doesn't fit. Use it to package more or different things (sandbox scripts, seed tooling, test dependencies) or to layer the image differently. Push it with--file, and add--target <stage>to stop at one stage of a multi-stage build.
Whichever you pick, the image must be linux/amd64 and glibc-based with bash, it needs its own WORKDIR such as
/app, and it must not end on a non-rootUSER. Runcofactor sandbox guide uploadfor the full rules. -
Plan before you build.
bashcofactor sandbox guide plan
-
Write
cofactor.sandbox.yaml. It matches the GitHub version withoutsetup, because the image is already built.lifecycle.buildis optional and runs only oncofactor sandbox sync --build.yamlversion: 1 resources: { vcpus: 2, memory_mib: 4096 } ports: web: { port: 8080, access: public } params: web_url: { port: web } env: PUBLIC_URL: ${params.web_url} services: app: run: exec ./start.sh health: { http: 8080, path: /health } reload_on_prepare: true personas: owner: { email: owner@example.test } lifecycle: prepare: - bash sandbox/personas.sh environments: default: description: One owner login and no data yet.Ship your sandbox scripts in the image. Seed data and logins covers personas, actions and seeds.
-
Check the file.
bashcofactor sandbox validate --upload cofactor.sandbox.yaml
-
Push. From the directory with your Dockerfile, Cofactor builds it for you.
bashcofactor sandbox push --application "Project Tracker" \ --definition cofactor.sandbox.yaml --tag nightly --wait
This uploads the files in the current directory that Cofactor doesn't have yet (
.dockerignoreapplies) and shows the build log. Use--context <dir>,--file <Dockerfile>and--target <stage>if your layout differs. For a sandbox Dockerfile in a subfolder, add--file sandbox/Dockerfile. It must sit inside the context.Already build the image yourself? Push it instead. Cofactor receives the built image and not your build context:
bashdocker buildx build --platform linux/amd64 -t tracker:sandbox --load . cofactor sandbox push --application "Project Tracker" tracker:sandbox \ --definition cofactor.sandbox.yaml --tag nightly --wait
Either way,
pushuploads only what Cofactor doesn't have. With--waitit follows the import until every service is healthy.The push output: layers uploaded, the image imported, then "ready [nightly, 2026-11-25]" and the claim command. -
Claim and prove it.
bashcofactor sandbox claim --application "Project Tracker" --wait cofactor sandbox verify-env --application "Project Tracker" cofactor sandbox destroy <sandbox id>
Push a new image every night
-
Create an API key in your own shell. The secret prints once, so keep it out of chat.
bashcofactor api-key create --name "CI image push" --scope sandbox:read --scope sandbox:publish --scope property:read
-
Store it as the repository secret
COFACTOR_API_TOKEN. -
Save this workflow as
.github/workflows/cofactor-sandbox-nightly.yml. ReplaceAcme Trackerwith your application's name.yamlname: Cofactor sandbox nightly on: schedule: - cron: "0 6 * * *" workflow_dispatch: permissions: contents: read jobs: push: runs-on: ubuntu-latest timeout-minutes: 60 steps: - uses: actions/checkout@v7 - uses: docker/setup-buildx-action@v4 - uses: docker/build-push-action@v7 with: context: . platforms: linux/amd64 load: true push: false tags: app:sandbox cache-from: type=gha cache-to: type=gha,mode=max - run: npm install -g @runcofactor/cli - env: COFACTOR_API_TOKEN: ${{ secrets.COFACTOR_API_TOKEN }} run: | cofactor sandbox validate --upload cofactor.sandbox.yaml cofactor sandbox push --application "Acme Tracker" app:sandbox \ --definition cofactor.sandbox.yaml --tag nightly --wait -
Run it once from the Actions tab, or with
gh workflow run cofactor-sandbox-nightly.yml.
Check it worked
The push ends with Push <id>: ready [nightly]. cofactor sandbox envs --application "Project Tracker" shows the version. After the first nightly run, claim last night's build with --at nightly. The claimed URL serves the app and each login signs in.
Performance
Cofactor boots your image when you push. The first claim of an environment runs lifecycle.prepare and the seeds and saves a snapshot of the running sandbox. Later claims are copies of that snapshot. These practices follow from that.
Keep pushes small
- Add a
.dockerignore. A push hashes every file the ignore file keeps and uploads the new ones, and refuses a context over 100,000 entries or 8 GiB. An unchanged context reuses the finished build, so keep out what the image doesn't use, such as.git, test output and docs. A<Dockerfile>.dockerignorebeside a sandbox Dockerfile wins over the context's.dockerignore. - Put what rarely changes first, if you build the image yourself. A pushed image's layers are named by the digest of their bytes, and
pushuploads only the ones Cofactor doesn't hold. Order system packages, then the dependency manifest and install, then your source. A Dockerfile push sends changed files in any order, and Cofactor's own build keeps no layer cache between builds. If your install steps are slow, build in CI with the cache and push the image. - Keep the build cache in CI. A runner with an empty cache rebuilds every step, and every rebuilt layer is new to Cofactor. See Build cache under Advanced.
Keep claims fast
- Build everything into the image. Nothing builds at claim, so install dependencies, compile assets and install any database server in the Dockerfile.
- Create data in seeds, not in
prepare. Seeds run once per version and environment, before the snapshot, and every copy shares the result.prepareruns for the snapshot and again for each copy, so keep it to logins and a few quick steps. - Skip the per-claim
preparewithliveport params. When every port param islive: true, a copy only receives its URLs: noprepare, no restart. Your app reads them at request time from/var/lib/cofactor/live-env.json. Runcofactor sandbox guide definitionfor the rules. - Make services start fast and answer
healthearly. Withoutliveparams, each copy restarts the services markedreload_on_prepareand waits for them to be healthy, checking every 200 ms for up to 5 minutes. A cheap/healththat answers as soon as the app is ready keeps each claim short. Mark only the services that read per-sandbox values. - Warm on disk, not in memory. Compile, migrate and fill on-disk caches in the Dockerfile or in a seed, and they are in every copy. A service that restarts on each claim starts with cold memory.
- Size
resourcesto the app. Every sandbox of the application gets that machine (1 to 32 vCPUs, 1,024 to 65,536 MiB). A size the fleet can't place fails the claim.
Keep the image lean
- Use a multi-stage build. Compile in a build stage and copy only the output into the final stage, so tools stay out of the image. Each layer can be up to 5 GB and an image up to 128 layers.
- Use
--targetfor variants. One Dockerfile can hold the production stage and asandboxstage that adds your scripts and seed tooling. Push thesandboxstage with--target sandbox.
Go deeper
Image rules, API key scopes, pull request tags and common errors.
Image rules. ENTRYPOINT and CMD are not used, so start each process with a services.<name>.run command. Everything runs as uid 1000. Run cofactor sandbox guide upload for the rest.
Tags. A push takes up to 10 tags. A tag names the newest ready push that carries it, so pushing --tag nightly again moves it. A claim without --at uses the newest ready push tagged main or nightly, or the newest ready push if none carries either tag.
Pull requests. An image gets no automatic PR preview. Push each pull request with its own tag, like --tag pr-123, and claim it with --at pr-123.
API key scopes.
| The job | Scopes |
|---|---|
| Pushes images | sandbox:read, sandbox:publish, property:read |
| Creates the application on first push | add property:create |
| Claims and destroys a sandbox | add sandbox:create, sandbox:delete |
| Runs actions | add sandbox:run |
| Runs a suite on the new push | add test-run:run, test-run:read |
Build cache. Use docker/build-push-action with type=gha. The cache works only from that action.
Errors. If push or a claim fails, the message names the cause and ends with the failing service's log or the script's stderr. Run cofactor upgrade if it says the server takes pushes from a newer CLI.