Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .claude/skills/commit/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ to the fctl session that made the change is welcome.
1. Branch from an up-to-date `main`: `<type>/<topic>` (`feat/postgres`), or
`fctl/<number>-<topic>` when an fctl session makes the branch.
2. Commit as you go; the commits are squashed, so the title is what lasts.
3. Run `shellcheck provision.sh check.sh check-fctl.sh` and `actionlint` if
you have them; the Lint workflow runs both anyway.
3. Run `shellcheck provision.sh check.sh check-fctl.sh kernel/build.sh
kernel/check.sh` and `actionlint` if you have them; the Lint workflow
runs both anyway.
4. Open the pull request with a conventional title and a description. One
change per pull request.
5. Wait for the checks in the same turn and fix failures (below).
Expand Down Expand Up @@ -83,6 +84,10 @@ gh pr checks N --watch --fail-fast
workflow change, and takes about a quarter of an hour. A step that the pull
request doesn't touch can fail because of fctl's `main`: the log names
the step.
- **Kernel** builds the kernel of fctl's Firecracker sandboxes for amd64
and arm64 and boots it with `kernel/check.sh` where the runner has KVM
(amd64's). It runs when `kernel/` or its workflow change, and takes about
ten minutes.
- **Lint** runs ShellCheck and actionlint.
- **Skills** validates every skill in `.claude/skills` against the
[Agent Skills specification](https://agentskills.io/specification). It
Expand Down
16 changes: 15 additions & 1 deletion .claude/skills/publish/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: publish
description: How the sandbox image reaches ghcr.io/hyperstructure/sandbox, and how to rebuild or repair it. Covers what starts the Image workflow (fctl releases, merges, Claude Code releases, the weekly rebuild), its tags and labels, running it by hand, checking a published image with or without Docker, and what to do when a run fails or the schedule stops. Use when asked to publish, rebuild or check the image, after merging a change to it, or when an fctl release has no image.
description: How the sandbox image reaches ghcr.io/hyperstructure/sandbox, and the kernel of fctl's Firecracker sandboxes ghcr.io/hyperstructure/sandbox-kernel, and how to rebuild or repair them. Covers what starts the Image workflow (fctl releases, merges, Claude Code releases, the weekly rebuild), its tags and labels, running it by hand, checking a published image with or without Docker, and what to do when a run fails or the schedule stops. Use when asked to publish, rebuild or check the image, after merging a change to it, or when an fctl release has no image.
---

# Publishing the image
Expand Down Expand Up @@ -90,6 +90,20 @@ curl -fsS -H "Authorization: Bearer $token" \
curl -fsS -H "Authorization: Bearer $token" https://ghcr.io/v2/hyperstructure/sandbox/tags/list
```

## The kernel

The Kernel workflow (`.github/workflows/kernel.yml`) publishes
`ghcr.io/hyperstructure/sandbox-kernel`, the kernel of fctl's Firecracker
sandboxes, from `main` only, the same way: it builds each architecture on
its own runner, boots it with `kernel/check.sh` where the runner has KVM
(amd64's), pushes both by digest and tags them as one image,
`<kernel/VERSION>` and `<major>.<minor>`. It runs when a push to `main`
changes `kernel/` and that version isn't published yet; a published
version is never built again, since hosts pin it and keep what they
pulled, so a change to the build takes a new version (`6.18.59-2`).
`gh workflow run kernel.yml` runs it again after a failure. Check what's
published as for the image, with `sandbox-kernel` in its name.

## When something fails

Publishing happens only after both architectures passed `check.sh`, so a
Expand Down
217 changes: 217 additions & 0 deletions .github/workflows/kernel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# Builds the kernel that fctl's firecracker driver boots its sandboxes with,
# for amd64 and arm64, boots it in Firecracker where the runner has KVM, and
# publishes it as ghcr.io/hyperstructure/sandbox-kernel:<kernel/VERSION> and
# :<major>.<minor>: an image whose /vmlinux is the kernel. fctl pins the
# version its hosts pull.
#
# - A push to main that changes kernel/ publishes the version in
# kernel/VERSION when it isn't published yet. A published version is never
# built again: hosts that pinned it keep the kernel they have, so a change
# to how it is built comes with a new version (6.18.59-2 for the same
# Linux release).
# - `gh workflow run kernel.yml` does the same, for a run that failed.
# - Pull requests that change kernel/ build and check it without publishing.
#
# Each architecture builds on its own runner and is pushed by digest, without
# a tag; the last job tags the two as one image. Only main publishes.
name: Kernel

on:
pull_request:
paths:
- kernel/**
- .github/workflows/kernel.yml
push:
branches: [main]
paths:
- kernel/**
- .github/workflows/kernel.yml
workflow_dispatch:

permissions:
contents: read

concurrency:
group: kernel-${{ github.event_name == 'pull_request' && github.ref || 'publish' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
IMAGE: ghcr.io/hyperstructure/sandbox-kernel
DESCRIPTION: The kernel of fctl's Firecracker sandboxes
SOURCE: https://github.com/hyperstructure/sandbox

jobs:
plan:
name: What to build
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: read
outputs:
version: ${{ steps.plan.outputs.version }}
tags: ${{ steps.plan.outputs.tags }}
created: ${{ steps.plan.outputs.created }}
build: ${{ steps.plan.outputs.build }}
push: ${{ steps.plan.outputs.push }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Version and tags
id: plan
env:
EVENT: ${{ github.event_name }}
GH_TOKEN: ${{ github.token }}
run: |
# The Linux release, and a build number when the build changed without one.
version=$(tr -d '[:space:]' < kernel/VERSION)
[[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?$ ]] || { echo "::error::kernel/VERSION says '$version'"; exit 1; }
IFS=. read -r major minor _ <<<"${version%%-*}"
tags="$IMAGE:$version $IMAGE:$major.$minor"

# Only main publishes; pull requests and other branches build and check.
push=no
if [ "$EVENT" != pull_request ] && [ "$GITHUB_REF" = refs/heads/main ]; then push=yes; fi

build=yes why="$IMAGE:$version isn't published yet"
if [ "$push" = yes ]; then
echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin >/dev/null
# Published: never again. GHCR denies a package it doesn't have
# yet; anything else (a 5xx, the network) stops the run, rather
# than publish over what may be there.
if inspected=$(docker buildx imagetools inspect --raw "$IMAGE:$version" 2>&1); then
build=no why="$IMAGE:$version is published already: a change to how it is built takes a new version in kernel/VERSION"
elif ! grep -qiE "not found|manifest unknown|name unknown|denied" <<<"$inspected"; then
echo "::error::Reading $IMAGE:$version: $inspected"
exit 1
fi
fi

{
echo "version=$version"
echo "tags=$tags"
echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "build=$build"
echo "push=$push"
} >> "$GITHUB_OUTPUT"
{
if [ "$build" = no ]; then
echo "Nothing to build: $why."
elif [ "$push" = yes ]; then
echo "Building Linux $version for \`$tags\`: $why."
else
echo "Building Linux $version from \`$GITHUB_REF\`, without publishing it."
fi
} >> "$GITHUB_STEP_SUMMARY"

build:
name: Build (${{ matrix.arch }})
needs: plan
if: needs.plan.outputs.build == 'yes'
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
permissions:
contents: read
packages: write
env:
VERSION: ${{ needs.plan.outputs.version }}
CREATED: ${{ needs.plan.outputs.created }}
PUSH: ${{ needs.plan.outputs.push }}
ARCH: ${{ matrix.arch }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Build
run: |
docker buildx create --name kernel --driver docker-container --use >/dev/null
docker buildx build kernel \
--platform "linux/$ARCH" --pull --provenance=false \
--output "type=local,dest=$RUNNER_TEMP/out"
ls -l "$RUNNER_TEMP/out"
- name: Boot it
shell: bash
run: |
# GitHub's x86_64 runners have KVM, for root only.
if [ -e /dev/kvm ]; then sudo chmod 666 /dev/kvm; fi
sudo apt-get install -y --no-install-recommends busybox-static >/dev/null
kernel/check.sh "$RUNNER_TEMP/out/vmlinux" | tee -a "$GITHUB_STEP_SUMMARY"
Comment thread
fctl-review[bot] marked this conversation as resolved.
Resolved
- name: Push it by digest
id: push
if: needs.plan.outputs.push == 'yes'
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin >/dev/null
# The same build again, from the builder's cache.
docker buildx build kernel \
--platform "linux/$ARCH" --provenance=false \
--label "org.opencontainers.image.title=sandbox-kernel" \
--label "org.opencontainers.image.description=$DESCRIPTION" \
--label "org.opencontainers.image.url=$SOURCE" \
--label "org.opencontainers.image.source=$SOURCE" \
--label "org.opencontainers.image.licenses=GPL-2.0-only" \
--label "org.opencontainers.image.version=$VERSION" \
--label "org.opencontainers.image.revision=$GITHUB_SHA" \
--label "org.opencontainers.image.created=$CREATED" \
--output "type=image,name=$IMAGE,push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true" \
--metadata-file "$RUNNER_TEMP/build.json"
digest=$(jq -r '."containerimage.digest"' "$RUNNER_TEMP/build.json")
mkdir -p "$RUNNER_TEMP/digests"
touch "$RUNNER_TEMP/digests/${digest#sha256:}"
- if: needs.plan.outputs.push == 'yes'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: kernel-digest-${{ matrix.arch }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

publish:
name: Publish
needs: [plan, build]
if: needs.plan.outputs.push == 'yes'
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
packages: write
env:
VERSION: ${{ needs.plan.outputs.version }}
CREATED: ${{ needs.plan.outputs.created }}
TAGS: ${{ needs.plan.outputs.tags }}
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: kernel-digest-*
path: ${{ runner.temp }}/digests
merge-multiple: true
- name: Tag both architectures as one image
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin >/dev/null
sources=()
for file in "$RUNNER_TEMP"/digests/*; do sources+=("$IMAGE@sha256:$(basename "$file")"); done
[ "${#sources[@]}" = 2 ] || { echo "::error::expected a digest for each architecture, got ${sources[*]}"; exit 1; }
tags=()
for tag in $TAGS; do tags+=(--tag "$tag"); done
# On the index too: GHCR shows these, and the next runs read the
# commit from them.
docker buildx imagetools create "${tags[@]}" \
--annotation "index:org.opencontainers.image.description=$DESCRIPTION" \
--annotation "index:org.opencontainers.image.source=$SOURCE" \
--annotation "index:org.opencontainers.image.licenses=GPL-2.0-only" \
--annotation "index:org.opencontainers.image.version=$VERSION" \
--annotation "index:org.opencontainers.image.revision=$GITHUB_SHA" \
--annotation "index:org.opencontainers.image.created=$CREATED" \
"${sources[@]}"
docker buildx imagetools inspect "$IMAGE:$VERSION"
{
echo "Published Linux $VERSION as:"
for tag in $TAGS; do echo "- \`$tag\`"; done
} >> "$GITHUB_STEP_SUMMARY"
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: ShellCheck
run: shellcheck --version && shellcheck provision.sh check.sh check-fctl.sh
run: shellcheck --version && shellcheck provision.sh check.sh check-fctl.sh kernel/build.sh kernel/check.sh
- name: actionlint
run: |
archive="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz"
Expand Down
16 changes: 15 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ to its code in hyperstructure/fctl.
| `check-fctl.sh` | Develops fctl in a built image, as sessions working on hyperstructure/fctl do. |
| `.github/workflows/image.yml` | Builds both architectures, checks them and publishes them. |
| `.github/workflows/fctl.yml` | On pull requests, runs `check-fctl.sh` in both architectures' builds. |
| `kernel/` | The kernel of fctl's Firecracker sandboxes: `build.sh` builds the Linux release in `VERSION` with Firecracker's guest configuration, `check.sh` boots it in Firecracker. |
| `.github/workflows/kernel.yml` | Builds the kernel for both architectures, boots it where there is KVM, and publishes it as `ghcr.io/hyperstructure/sandbox-kernel`. |
| `.github/workflows/lint.yml`, `commits.yml`, `skills.yml` | ShellCheck and actionlint; pull request titles; the skills, against the Agent Skills specification. |
| `.claude/skills/` | How to change the image, publish it, and commit. |

Expand All @@ -28,7 +30,8 @@ docker build -t sandbox:dev . # your architectu
docker build -t sandbox:dev --build-arg FCTL_VERSION=0.3.0 . # with another fctl
docker run --rm -i sandbox:dev sh -s < check.sh # check the layout
docker run --rm -i --init sandbox:dev bash -s < check-fctl.sh # develop fctl in it
shellcheck provision.sh check.sh check-fctl.sh
kernel/build.sh && kernel/check.sh out/vmlinux # the kernel (Linux; booting needs /dev/kvm)
shellcheck provision.sh check.sh check-fctl.sh kernel/build.sh kernel/check.sh
actionlint # the workflows
```

Expand Down Expand Up @@ -71,6 +74,17 @@ pull request.
Release workflow starts `.github/workflows/image.yml` with
`-f version=<fctl version>` for each release, as the fctl-actions GitHub
App, and fails its Sandbox image job when the run fails.
- **The kernel image.** fctl's firecracker driver pulls
`ghcr.io/hyperstructure/sandbox-kernel:<version>`, the version each fctl
release pins, and boots the file `/vmlinux` in it: an uncompressed kernel
(x86_64's ELF `vmlinux`, aarch64's `Image`) with everything built in, and
with ext4, overlayfs, virtio's MMIO devices, vsock and TAP devices, which
its init needs (`kernel/check.sh` checks them). Publish a tag before fctl
pins it. A tag never moves (the Kernel workflow builds no published
version again): a change to how the kernel is built takes a new version
in `kernel/VERSION`, `6.18.59-2` for the same Linux release. The same
hosts boot this image's layout as a VM, with fctl-agent as its init
rather than a container's: the layout above holds for them too.
- **Subscriptions only.** fctl runs Claude Code on Claude subscriptions,
never on API billing. Never set `ANTHROPIC_*` variables, an
`apiKeyHelper`, or Bedrock, Vertex or Foundry switches in the image.
Expand Down
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,44 @@ web app with Playwright. It checks hyperstructure/fctl's branch of the pull
request's name when there is one (an fctl session that changes both
repositories names their branches alike), and `main` otherwise.

## The kernel

fctl's `firecracker` driver runs each session in a
[Firecracker](https://firecracker-microvm.github.io) microVM, made from this
image, which boots a kernel published from here too:

```sh
docker buildx imagetools inspect ghcr.io/hyperstructure/sandbox-kernel:6.18.59
```

It is Linux's long-term release in [`kernel/VERSION`](kernel/VERSION),
configured as Firecracker configures its own CI's guests
([`kernel/microvm-x86_64.config`](kernel/microvm-x86_64.config) and
[`kernel/microvm-aarch64.config`](kernel/microvm-aarch64.config), from
Firecracker's `resources/guest_configs`): every driver built in, with ext4,
overlayfs, vsock, TAP devices, cgroups, nftables and the balloon's free
page reporting. [`kernel/fctl.config`](kernel/fctl.config) adds only
`/proc/config.gz`. The image holds the kernel as `/vmlinux`, and its
configuration as `/vmlinux.config`.

| Tag | Kernel |
|---|---|
| `6.18.59` | Linux 6.18.59. Each fctl release pins the one its hosts boot. A tag never moves: a change to how the kernel is built takes a new one, `6.18.59-2` for the same release. |
| `6.18` | The newest 6.18 built here. |

```sh
kernel/build.sh # out/vmlinux, on Linux, for this machine
docker build --output type=local,dest=out kernel # the same, in a container
kernel/check.sh out/vmlinux # boots it in Firecracker, with /dev/kvm
```

The Kernel workflow ([`.github/workflows/kernel.yml`](.github/workflows/kernel.yml))
builds it for both architectures, boots it where the runner has KVM (amd64's),
and publishes a version of `kernel/VERSION` that isn't published yet when
`kernel/` changes on `main`. A new kernel release is a change to
`kernel/VERSION` and `kernel/SHA256SUMS` (from kernel.org's
`sha256sums.asc`), and then one to the version fctl pins.

## Questions and changes

Open an issue for a tool the image lacks or something that doesn't work in
Expand All @@ -190,7 +228,10 @@ agents.

## License

The files in this repository are under the [MIT license](LICENSE). The image
contains software under its own licenses, among them Claude Code, which
The files in this repository are under the [MIT license](LICENSE), but for
`kernel/microvm-*.config`, which come from Firecracker, under the Apache
License 2.0. The image contains software under its own licenses, among them
Claude Code, which
[Anthropic's terms](https://code.claude.com/docs/en/legal-and-compliance)
govern.
govern. The kernel is Linux, under the GPL 2.0: its source is the release on
kernel.org that `kernel/VERSION` names, built with `kernel/build.sh`.
17 changes: 17 additions & 0 deletions kernel/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The kernel of fctl's Firecracker sandboxes, as an image whose /vmlinux it
# is: fctl hosts with the firecracker driver pull it and boot their VMs
# with it. .github/workflows/kernel.yml publishes it as
# ghcr.io/hyperstructure/sandbox-kernel.
#
# docker build -t sandbox-kernel:dev kernel
# docker build --output type=local,dest=out kernel # out/vmlinux
FROM debian:trixie-slim AS build
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bc bison build-essential ca-certificates curl flex libelf-dev libssl-dev xz-utils \
&& rm -rf /var/lib/apt/lists/*
COPY . /kernel
RUN OUT=/out /kernel/build.sh

FROM scratch
COPY --from=build /out/vmlinux /out/vmlinux.config /
1 change: 1 addition & 0 deletions kernel/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53a55ac9863a5547e292b8e381d4e4c2240dd1127d5428a7c44dbc550be23963 linux-6.18.59.tar.xz
1 change: 1 addition & 0 deletions kernel/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.18.59
Loading