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: 6 additions & 3 deletions .claude/skills/commit/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +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 kernel/build.sh
kernel/check.sh` and `actionlint` if you have them; the Lint workflow
runs both anyway.
3. Run `shellcheck provision.sh check.sh check-fctl.sh examples/check.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 @@ -88,6 +88,9 @@ gh pr checks N --watch --fail-fast
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.
- **Examples** builds the images in `examples/` for amd64 and arm64 and
runs `examples/check.sh` in each. It runs when `examples/` or its
workflow change, and takes a few 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
55 changes: 55 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Builds the images in examples/, which fctl's docs show (Sandbox images, An
# image from another base), for amd64 and arm64, and checks each with
# examples/check.sh, as the user fctl sessions run as. Nothing is published.
name: Examples

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

permissions:
contents: read

concurrency:
group: examples-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
name: ${{ matrix.example }} (${{ matrix.arch }})
strategy:
fail-fast: false
matrix:
example: [ubuntu]
arch: [amd64, arm64]
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Build
env:
EXAMPLE: ${{ matrix.example }}
run: docker build --pull -t "example:$EXAMPLE" "examples/$EXAMPLE"
- name: Check it
env:
EXAMPLE: ${{ matrix.example }}
run: |
docker run --rm -i --entrypoint sh "example:$EXAMPLE" -s < examples/check.sh
# A new volume at /var/cache/fctl, as fctl mounts package caches,
# is the user's without a chown.
cache="fctl-example-cache-$EXAMPLE-$GITHUB_RUN_ID"
docker run --rm --mount "type=volume,source=$cache,target=/var/cache/fctl" "example:$EXAMPLE" touch /var/cache/fctl/written
docker volume rm "$cache"
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 kernel/build.sh kernel/check.sh
run: shellcheck --version && shellcheck provision.sh check.sh check-fctl.sh examples/check.sh kernel/build.sh kernel/check.sh
- name: actionlint
run: |
archive="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz"
Expand Down
4 changes: 3 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ to its code in hyperstructure/fctl.
| `provision.sh` | Installs everything, as root. The versions are at the top. |
| `check.sh` | Checks a built image for the layout fctl and derived images rely on. |
| `check-fctl.sh` | Develops fctl in a built image, as sessions working on hyperstructure/fctl do. |
| `examples/` | Images that don't start from this one, which fctl's docs show (`ubuntu/Dockerfile`), and `check.sh`, which checks any image for what fctl needs of it. |
| `.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. |
| `.github/workflows/examples.yml` | Builds the examples for both architectures and checks them with `examples/check.sh`, when they change. |
| `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. |
Expand All @@ -31,7 +33,7 @@ docker build -t sandbox:dev --build-arg FCTL_VERSION=0.3.0 . # with another fc
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
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
shellcheck provision.sh check.sh check-fctl.sh examples/check.sh kernel/build.sh kernel/check.sh
actionlint # the workflows
```

Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ To run it in fctl, name it in a project's Settings → Sandbox → Image, or as
([Sandbox images](https://fctl.sh/docs/sandbox-images/) in fctl's docs).
Apple silicon hosts need arm64 images.

## Another base

An image that doesn't start from this one, such as a company's own on
Ubuntu, runs fctl sessions once it has fctl, Claude Code, git, gh, bash and
a user other than root. It needs no fctl-agent: the host copies its own
into each sandbox when a session starts there.
[`examples/ubuntu/Dockerfile`](examples/ubuntu/Dockerfile) makes Ubuntu
24.04 into such an image, to add your own packages and steps to, and
[`examples/check.sh`](examples/check.sh) checks an image for what fctl
needs, as the user sessions run as:

```sh
docker build -t my-sandbox examples/ubuntu
docker run --rm -i --entrypoint sh my-sandbox -s < examples/check.sh
```

The Examples workflow builds and checks the example for both
architectures when it changes. fctl's docs explain each step, and what to
do on other distributions:
[An image from another base](https://fctl.sh/docs/sandbox-images/#an-image-from-another-base).

## Building it

```sh
Expand Down
91 changes: 91 additions & 0 deletions examples/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/sh
# Checks an image that doesn't start from this one for what fctl needs of
# it (fctl's docs: https://fctl.sh/docs/sandbox-images/#what-an-image-needs).
# Runs inside the image as its user, in place of its ENTRYPOINT, as sessions
# do:
#
# docker run --rm -i --entrypoint sh IMAGE -s < examples/check.sh
#
# It fails on what sessions can't do without, warns about the rest, and needs
# the network, to reach GitHub as git does.
set -u

failed=0 claude='' fctl_version=''
fail() {
echo "check.sh: $*" >&2
failed=1
}
warn() { echo "check.sh: warning: $*" >&2; }

# Whether version $1 (2.1.101) is older than $2.
older() {
# shellcheck disable=SC2046 # split at the dots
set -- $(echo "$1 $2" | tr . ' ')
[ "$1" -lt "$4" ] || { [ "$1" -eq "$4" ] && { [ "$2" -lt "$5" ] || { [ "$2" -eq "$5" ] && [ "$3" -lt "$6" ]; }; }; }
}

# What the host runs in the sandbox itself, by the system's own directories.
[ -x /bin/sh ] || fail "/bin/sh is missing"
for tool in tail id cat mkdir chown chmod mv rm stat; do
found=
for dir in /usr/sbin /usr/bin /sbin /bin; do
[ ! -x "$dir/$tool" ] || found=yes
done
[ -n "$found" ] || fail "$tool is not in /usr/bin or /bin"
done

# The user Claude and its commands run as, and its home, from /etc/passwd as
# fctl-agent reads it.
uid=$(id -u)
[ "$uid" != 0 ] ||
warn "the image runs as root, so Claude does, and its commands can stop fctl-agent: end the Dockerfile with USER and a user of its own"
home=
while IFS=: read -r _ _ id _ _ dir _; do
if [ "$id" = "$uid" ]; then
home=$dir
break
fi
done </etc/passwd
if [ -z "$home" ]; then
fail "uid $uid has no line in /etc/passwd, so sessions would have / as their home"
elif [ ! -d "$home" ] || [ ! -w "$home" ]; then
fail "$home, the home of uid $uid, is missing or not writable"
fi

# What Claude and the setup script find: the image's PATH, and a login
# shell's, which the setup script runs in.
for tool in bash git claude fctl; do
command -v "$tool" >/dev/null 2>&1 || fail "$tool is not on the PATH ($PATH)"
done
command -v gh >/dev/null 2>&1 || warn "gh is not on the PATH, so sessions show no pull request"
if command -v bash >/dev/null 2>&1; then
for tool in git claude fctl; do
if command -v "$tool" >/dev/null 2>&1 && ! bash -lc "command -v $tool" >/dev/null 2>&1; then
fail "$tool is not on a login shell's PATH ($(bash -lc 'printf %s "$PATH"'))"
fi
done
fi

if command -v claude >/dev/null 2>&1; then
# `2.1.302 (Claude Code)`
claude=$(claude --version 2>/dev/null)
claude=${claude%% *}
case $claude in
[0-9]*.[0-9]*.[0-9]*)
! older "$claude" 2.1.101 || fail "Claude Code is $claude: fctl needs 2.1.101 or later"
;;
*) fail "claude --version says '$claude'" ;;
esac
fi
if command -v fctl >/dev/null 2>&1; then
fctl_version=$(fctl --version 2>/dev/null) || fail "fctl --version fails: is it the build for this architecture?"
fi

[ -w /var/cache/fctl ] ||
warn "the user can't write to /var/cache/fctl, where fctl mounts the project's package caches, so on hosts that run nothing as root its package managers keep their own"
if command -v git >/dev/null 2>&1 && ! git ls-remote https://github.com/hyperstructure/sandbox HEAD >/dev/null 2>&1; then
fail "git can't reach GitHub over HTTPS: are CA certificates installed?"
fi

[ "$failed" = 0 ] || exit 1
echo "The image has what fctl needs, with ${fctl_version:-fctl} and Claude Code $claude, as uid $uid in $home."
50 changes: 50 additions & 0 deletions examples/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# An image for fctl sessions that doesn't start from fctl's own: Ubuntu with
# what fctl needs, to which you add what your sessions need. fctl's docs
# explain each step: https://fctl.sh/docs/sandbox-images/#an-image-from-another-base
#
# docker build -t my-sandbox examples/ubuntu
# docker run --rm -i --entrypoint sh my-sandbox -s < examples/check.sh
FROM ubuntu:24.04

# A download piped into a shell fails the step when it fails.
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8

# What fctl needs: bash, git, curl and CA certificates (for the installers,
# and git over HTTPS), and the GitHub CLI from GitHub's repository. sudo lets
# the agent install what a task needs: the sandbox is the boundary. Add your
# own packages to the list.
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates curl git sudo \
&& curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
-o /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
> /etc/apt/sources.list.d/github-cli.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends gh \
&& rm -rf /var/lib/apt/lists/*

# fctl, for every user: a static build, which runs on any Linux. An empty
# FCTL_VERSION installs the latest release. The host puts its own fctl-agent
# into the sandbox each time a session starts, so the archive's goes.
ARG FCTL_VERSION=
RUN curl -fsSL https://fctl.sh/install \
| env FCTL_VERSION="$FCTL_VERSION" FCTL_INSTALL_DIR=/usr/local/bin FCTL_NO_COMPLETIONS=1 sh \
&& rm -f /usr/local/bin/fctl-agent-*-linux

# The user sessions run as, with sudo and the package caches' directory.
# Ubuntu's images come with the user ubuntu at uid 1000: agent takes its
# place.
RUN if id ubuntu >/dev/null 2>&1; then userdel --remove ubuntu; fi \
&& useradd --create-home --shell /bin/bash --uid 1000 agent \
&& echo 'agent ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/agent \
&& chmod 0440 /etc/sudoers.d/agent \
&& install -d -o agent -g agent /var/cache/fctl

# Claude Code, the native build, in ~/.local/bin, as the user. Claude and its
# commands find their tools through the image's PATH, and so do setup
# scripts: Ubuntu's login shells keep it.
Comment on lines +44 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment wrongly says login shells keep the image's PATH

Low severity. Ubuntu's /etc/profile rebuilds PATH from a fixed list, so a login shell does not keep ENV PATH; ~/.local/bin only survives because /etc/skel/.profile re-adds it when the directory exists. Someone who follows "add your own steps" and adds ENV PATH=/opt/tool/bin:$PATH finds the tool in Claude but not in setup scripts, which run in a login shell, and examples/check.sh only tests git, claude and fctl, so it passes. The main image avoids this with /etc/profile.d/fctl.sh (provision.sh), and AGENTS.md says the PATH must match in both places.

Suggested change
# Claude Code, the native build, in ~/.local/bin, as the user. Claude and its
# commands find their tools through the image's PATH, and so do setup
# scripts: Ubuntu's login shells keep it.
# Claude Code, the native build, in ~/.local/bin, as the user. Claude and its
# commands find their tools through the image's PATH. Setup scripts run in
# login shells, which on Ubuntu rebuild PATH from /etc/profile: ~/.local/bin
# survives through ~/.profile, but a directory you add with ENV PATH needs a
# file in /etc/profile.d/ too.

Found by fctl review in b81e8e8.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, so I've left the comment as it is. Ubuntu 24.04's /etc/profile doesn't set PATH: it only sources /etc/bash.bashrc for interactive shells and /etc/profile.d/*.sh. Debian's /etc/profile is the one that rebuilds PATH from a fixed list, and so does Alpine's. I checked this in the example image built from this branch, with an extra directory on the image's PATH as the finding describes:

image: /opt/tool/bin:/home/agent/.local/bin:/usr/local/bin:/usr/bin:/bin
login: /home/agent/.local/bin:/opt/tool/bin:/home/agent/.local/bin:/usr/local/bin:/usr/bin:/bin

The login shell keeps /opt/tool/bin; ~/.profile only adds ~/.local/bin in front again. fctl's docs (hyperstructure/fctl#610) make the same distinction: Ubuntu's login shells keep the image's PATH, while images on Debian or Alpine need /etc/profile.d, as the default image has it. examples/check.sh caught exactly that on an Alpine build.

USER agent
WORKDIR /home/agent
RUN curl -fsSL https://claude.ai/install.sh | bash
ENV PATH=/home/agent/.local/bin:$PATH