Skip to content

feat(host): refresh the default sandbox image and remove old ones - #89

Merged
kalaspuff merged 5 commits into
mainfrom
fctl/43-can-you-look-into-https-github-com-hyper
Oct 18, 2026
Merged

kalaspuff merged 5 commits into
mainfrom
fctl/43-can-you-look-into-https-github-com-hyper

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Hosts on the default sandbox image pulled their tag once and kept it. hyperstructure/sandbox's Image workflow rebuilds the newest release's image when Claude Code has a newer release, since fctl turns off Claude Code's auto-updater. But a host that already had the tag kept its first pull until it was upgraded or someone ran fctl host image pull, so its sessions' Claude Code aged between upgrades anyway. And every upgrade left the previous version's image on the host, as did the latest a host pulls while its release's image isn't published yet. Nothing removed them.

The two decisions #47 left to a person were made in this session, and are recorded in the issue. The host tells a local build from the published image by the org.opencontainers.image.revision label, which only the Image workflow sets. It pulls again at start and every 6 hours.

What changed

Refreshing (crates/fctl-host/src/refresh.rs, daemon.rs). The host's background pull used to run once, at start, and only for a missing image. Now it runs at start and every 6 hours:

  • An image that isn't here is pulled as before, falling back to latest while the version's image can't be pulled.
  • On the default image, the host pulls its tag again, so new sessions start from the newest build. Sessions never wait for it: they start from the build that is there. When the tag hasn't changed, the pull costs one manifest request.
  • It never pulls over an image without the revision label. That covers builds from fctl host image build or by hand: the sandbox's Dockerfile sets no labels, and its base, debian:bookworm-slim, has none. An image whose description can't be read counts as a local build, so the host leaves it alone, as it did before.
  • A host whose host.toml sets another image pulls it only when it isn't there, as before.

Removing (refresh::clean_up). At start, after each pull and after sweeps that remove sandboxes, the host removes these, without force:

  • builds that a newer one replaced;
  • other versions' images (X.Y.Z tags);
  • latest, once the version's image is here. Until then, sessions start from it.

Images without the revision label stay, and so do tags hosts don't pull, like 0.5, which projects may use. A host on another image removes nothing.

How a replaced build stays findable. A pull that moves a tag leaves the old build without a name. Docker keeps it as <none>, and with the containerd image store nothing finds that again by name. Apple's container keeps its blobs and snapshot orphaned until an image delete runs its cleanup. So before a pull (or fctl host image build) replaces a published build, the host gives that build a second name, <tag>-replaced-<the start of its ID>, and removes the name right after:

  • If the build is unchanged, removing the name only untags it.
  • If it was replaced and nothing uses it, the build goes.
  • With Docker, if it was replaced and a sandbox still uses it, Docker refuses. The name stays until a cleanup after the sweep removes that sandbox (keep_stopped_hours).

This needs no state file, and a host that stops halfway leaves a name the cleanup finds. A name whose build is still the one sessions start from is left alone, so a cleanup that runs during a pull can't strand the build.

Apple. container image delete doesn't check whether a container uses the image. It's still safe: each container gets a clone of the image's filesystem when it is created (Bundle.cloneContainerRootFs in apple/container), and starting it again uses only that clone. So on Apple the host removes these right away, and stopped sandboxes still start.

Driver (driver/container.rs, driver/mod.rs):

  • image: ID and labels from image inspect, in Docker's, Podman's and both of Apple's shapes (its JSON changed at 1.0).
  • tag_image.
  • remove_image: image rm or image delete, never forced.
  • images: image ls --format … or image list --quiet.

CLI (crates/fctl/src/cmd/host.rs):

  • fctl host image pull also removes what sessions no longer start from, and says what it did:

    ✓ Pulled ghcr.io/hyperstructure/sandbox:0.5.0, a newer build (Claude Code 2.1.310)
      Removed ghcr.io/hyperstructure/sandbox:0.4.0
      The build it replaced stays until no sandbox uses it; the host removes it then.
    

    --json adds newer (whether the pull brought a newer build) and removed (the names it removed) to image and instead_of.

  • fctl host doctor shows the image's Claude Code version, or that the host doesn't pull over a local build:

    ✓ sandbox image ghcr.io/hyperstructure/sandbox:0.5.0 (Claude Code 2.1.310)
    ✓ sandbox image ghcr.io/hyperstructure/sandbox:0.5.0 (built here: the host doesn't pull over it)
    

Docs:

  • docs/sandbox-images.md says when the host pulls again, how it tells a local build, and what it removes and when, with Docker and with Apple.
  • docs/architecture.md and docs/cli.md say the same briefly.
  • AGENTS.md lists the revision label among what the host relies on in hyperstructure/sandbox. docs: say that fctl hosts rely on the revision label sandbox#3 does the same there.

Tests. The driver tests' stand-in for the docker and container CLIs moved to driver/fake.rs, shared by the driver tests, these tests and #88's build tests. It gained image IDs, labels, tags, listing, and Docker's refusal to remove an image's last name while a container uses it. It keeps #88's builds, image sizes and failing builds.

With #88. main gained #88 (projects' own images and builds) while this was open, and is merged in. Both added the same remove_image to the driver, so one stays. Project images and builds aren't the default image, so the host doesn't pull them again here or remove them in this cleanup: #88 keeps each project's newest build itself.

Compatibility

This changes only the host: no protocol or control-plane change, and it reaches hosts with the next release. fctl host image pull --json gains two fields.

  • At its first start after the upgrade, a host removes the previous version's image, unless a stopped sandbox uses it (Docker).
  • Builds that earlier pulls left as <none> stay: nothing tells them from other unnamed images.
  • Two hosts sharing one Docker daemon on different versions would each remove the other's image when no sandbox uses it, and pull it again later. That costs extra downloads; nothing breaks.

Verification

  • Unit tests: 14 new; fctl-host has 57 with feat: let hosts allow and build projects' sandbox images #88's.

    • removable: what goes and what stays, including latest before and after the version's image arrives, local builds, X.Y tags, and a replaced name whose build is still current.
    • Version tags, replaced names, and inspect output from Docker, Podman, Apple 0.x and Apple 1.x.
    • Flows against the stand-in:
      • a newer build replaces one a stopped sandbox uses, which goes once the sandbox is gone;
      • an unchanged build is only tagged and untagged;
      • the host never pulls over a local build, and fctl host image pull does;
      • a build over the published image (and a failed one);
      • latest going once the version's image is published;
      • other versions going after an upgrade, unless in use;
      • Apple removing a replaced build that a sandbox was made from;
      • a host on another image doing nothing.
  • The published image (read from ghcr.io anonymously): the config of ghcr.io/hyperstructure/sandbox:0.5.0 has org.opencontainers.image.revision (12685ad…) and sh.fctl.claude-code.version (2.1.302). debian:bookworm-slim, the base of local builds, has no labels.

  • With real Podman (rootless, FCTL_DOCKER_BIN=podman): I imported images of a few KB under the default image's names. The host's 0.5.0 was a local build, and a stopped fctl-ses-… container used 0.3.0. fctl host run:

    • logged that it doesn't pull over the local build;
    • removed 0.4.0 (only untagged, since 0.4 names the same build), latest, and a 0.5.0-replaced-… build;
    • kept 0.3.0 because Podman refused ("image is in use by a container"), and kept the local 0.2.0 and the 0.4 tag.

    fctl host doctor said "built here: the host doesn't pull over it".

  • With the stand-in CLI (FCTL_DOCKER_BIN), the real binary:

    • fctl host image pull printed the output above.
    • Once the sandbox was gone, fctl host image pull --json printed {"image": "ghcr.io/hyperstructure/sandbox:0.5.0", "instead_of": null, "newer": false, "removed": ["ghcr.io/hyperstructure/sandbox:0.5.0-replaced-0a1d00000000"]}.
    • fctl host run logged pulled a newer build of ghcr.io/hyperstructure/sandbox:0.5.0 (Claude Code 2.1.310), kept the replaced build while a sandbox used it, and removed 0.4.0.
    • doctor showed the Claude Code version.
  • cargo xtask check --quick passes, before and after merging main. I reran the Podman check on the merged binary, with the same result.

  • Not run here: Docker itself (this sandbox can't run a Docker daemon) and Apple's container (that needs a Mac). The commands are the documented ones. I read the behaviors this relies on in their sources:

    • Docker refuses, without force, to remove an image's last name while a container uses it, in both image stores, and moby's containerd store counts its moby-dangling@… records as that same name (daemon/images/image_delete.go, daemon/containerd/image_delete.go).
    • In apple/container, a container keeps its own clone of the image's filesystem, a pull leaves the old build orphaned until image delete cleans up, and image tag overwrites an existing name.

    Trying the first release on a Docker host and on a Mac is the check that's left.

Fixes #47

Session: https://app.fctl.sh/s/ses_01M5813Y3P1VY7K0ZSS6PKRS9V

fctl-sh Bot added 3 commits October 18, 2026 18:21
A host on the default image pulled its tag once, so its sessions' Claude
Code aged between upgrades although the Image workflow rebuilds the
image, and every upgrade left the previous version's image behind.

The host now pulls its tag again when it starts and every 6 hours, unless
the image there has no org.opencontainers.image.revision label, which
only the Image workflow sets: then it was built on the host. A published
build that a pull (or fctl host image build) replaces keeps a name,
<tag>-replaced-<id>, and the host removes those, other versions' images
and latest (once the version's image is here) without force, at start,
after each pull and after sweeps that remove sandboxes. Docker keeps an
image a sandbox uses until the sweep removes the sandbox; Apple's
container gives each container its own copy of the image's filesystem.

fctl host image pull removes them too and says what it removed, and
fctl host doctor shows the image's Claude Code version, or that the host
doesn't pull over a local build.
docs/sandbox-images.md says when the host pulls its tag again, how it
tells a local build (the revision label), and which default images it
removes, when, and why stopped sandboxes keep theirs with Docker but not
with Apple's container. The architecture and CLI pages say so briefly.
Hosts now pull their tag again over, and remove, only images that carry
org.opencontainers.image.revision, which only hyperstructure/sandbox's
Image workflow sets, so that label is part of the interface between the
two repositories.
fctl-sh Bot added 2 commits October 18, 2026 18:41
Resolves the conflicts with #88. Its build tests and the image refresh's
share one stand-in CLI, driver/fake.rs, which gains #88's builds, image
sizes and failing builds; the two remove_image methods it and this branch
added were the same, so one stays. docs/sandbox-images.md keeps #88's
wording for project images, and says that a host on another image removes
none of the default image's: it does remove old project builds.
kalaspuff pushed a commit to hyperstructure/sandbox that referenced this pull request Oct 18, 2026
fctl hosts now pull their own version's tag again every 6 hours, so new
sessions start from the newest build, with the newest Claude Code. They
also remove the images sessions no longer start from: other versions'
images, builds that a newer one replaced, and `latest` once their own
version's image is there (hyperstructure/fctl#89, for
hyperstructure/fctl#47).

A host tells a published image from one built on the host by
`org.opencontainers.image.revision`, which only the Image workflow sets
(`docker buildx build --label …`). The `Dockerfile` sets no labels, and
its base, `debian:bookworm-slim`, has none. A host never pulls over or
removes an image without the label. So the label, and the `Dockerfile`
not setting it, are now part of what fctl relies on:

- AGENTS.md lists the label under "What fctl relies on", and its item on
the tags says what hosts do with them now.
- README.md's table of labels says that images built elsewhere have
none.

This is documentation only: the Image workflow doesn't run, and the
image doesn't change.

Refs hyperstructure/fctl#47

Session: https://app.fctl.sh/s/ses_01M5813Y3P1VY7K0ZSS6PKRS9V

Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
@kalaspuff
kalaspuff merged commit 12e285e into main Oct 18, 2026
5 of 6 checks passed
@kalaspuff
kalaspuff deleted the fctl/43-can-you-look-into-https-github-com-hyper branch October 18, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Hosts never refresh a rebuilt sandbox image or remove old ones

1 participant