Repository navigation
docs: show how to run fctl sessions in an image on another base #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kalaspuff
merged 2 commits into
main
from
fctl/1526-it-should-be-documented-in-our-docs-and
Nov 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| USER agent | ||
| WORKDIR /home/agent | ||
| RUN curl -fsSL https://claude.ai/install.sh | bash | ||
| ENV PATH=/home/agent/.local/bin:$PATH | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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/profilerebuildsPATHfrom a fixed list, so a login shell does not keepENV PATH;~/.local/binonly survives because/etc/skel/.profilere-adds it when the directory exists. Someone who follows "add your own steps" and addsENV PATH=/opt/tool/bin:$PATHfinds the tool in Claude but not in setup scripts, which run in a login shell, andexamples/check.shonly 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 thePATHmust match in both places.Found by fctl review in
b81e8e8.There was a problem hiding this comment.
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/profiledoesn't setPATH: it only sources/etc/bash.bashrcfor interactive shells and/etc/profile.d/*.sh. Debian's/etc/profileis the one that rebuildsPATHfrom 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:The login shell keeps
/opt/tool/bin;~/.profileonly adds~/.local/binin 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.shcaught exactly that on an Alpine build.