diff --git a/docs/README.md b/docs/README.md index 4a972406..2d590830 100644 --- a/docs/README.md +++ b/docs/README.md @@ -39,7 +39,7 @@ Three pieces make up a factory: | Run your own instance, on a machine of yours or on Cloudflare | [Self-hosting](self-hosting.md) | | Run fctl for an organization: accounts from your directory, agents started from your own portal or bot, webhooks to your tools | [fctl for organizations](organizations.md) | | Let agents prove who they are to your own services with OIDC tokens, and reach AWS, Google Cloud and Azure without keys | [Identity tokens](identity-tokens.md) | -| Know what sessions run in, give a project its own image, or choose the images a host runs | [Sandbox images](sandbox-images.md) | +| Know what sessions run in, give a project its own image (on the default one or on another base, such as Ubuntu), or choose the images a host runs | [Sandbox images](sandbox-images.md) | | Understand how the pieces talk to each other | [Architecture](architecture.md) | | Know what fctl does with your credentials | [Security](security.md) | | Work on fctl itself | [Development](development.md) | diff --git a/docs/llms.txt b/docs/llms.txt index 7da07d8f..2827bc40 100644 --- a/docs/llms.txt +++ b/docs/llms.txt @@ -48,7 +48,7 @@ web app · fctl CLI · HTTP API · Claude apps · Linear · GitHub webhooks - **Enrollment token** (`fctl_et_…`, id `enr_…`): a workspace's token with which machines enroll themselves as its runners without anyone signing in (`fctl host install --enroll`), as autoscaling creates them. Each machine gets a runner token of its own. A token has an expiry, a limit on its runners at once, and may make each runner wait for approval or remove runners that stay offline. Admins make them for everyone's sessions; any member makes one for their own (`--personal`), whose runners are theirs, count for Only on my runners and a Claude token kept on runners, and wait for their approval. - **Host**: the `fctl host` service on a runner, and the commands that install and look after it on that machine (`fctl host install|status|doctor|drain|uninstall`). It is not a group of runners: one machine is one runner, and its sandboxes all come from one driver. **Driver**: how a host makes sandboxes: `apple` (a lightweight VM per session, Apple silicon, macOS 26+), `lima` (a full VM), `docker` (a container; on macOS inside Docker's VM), `firecracker` (a microVM per session with a kernel of its own, Linux with KVM, chosen with `--driver firecracker`), `process` (no isolation, development only). - **Sandbox**: the VM or container a session runs in. Its user is `agent`, the repository is at `~/workspace`, other repositories go in `~/repos//`, attachments in `~/attachments/`. A stopped session keeps its sandbox (72 hours by default) so a resume continues the same conversation. -- **Image**: what sandboxes start from: `ghcr.io/hyperstructure/sandbox:` by default (Debian with git, gh, Python and uv, Rust, Node.js, TypeScript, Bun, Playwright with its browsers, Claude Code and fctl), or the project's own, or one built from a Dockerfile or devcontainer.json in its repository. +- **Image**: what sandboxes start from: `ghcr.io/hyperstructure/sandbox:` by default (Debian with git, gh, Python and uv, Rust, Node.js, TypeScript, Bun, Playwright with its browsers, Claude Code and fctl), or the project's own, or one built from a Dockerfile or devcontainer.json in its repository. An image on another base (Ubuntu, say) needs fctl, Claude Code, git, gh, bash and a user other than root, but no fctl-agent, which the host copies into each sandbox. - **Claude connection** (`crd_…`): a person's Claude subscription credential: a full Claude login (Remote Control works), a long-lived token from `claude setup-token`, or a token kept on their runners that fctl never sees. - **Access token** (`fctl_pat_…`, id `tok_…`): a token for scripts, CI, bots and other agents, optionally limited to reading, running sessions or everything, to some projects or workspaces, and in what its sessions' agents may do on GitHub. - **Service account** (`fctl_svc_…`, id `sva_…`): a workspace's credential for a program of its own (a portal where people start agents, a chat bot, a script). Each request names the person it acts for (`Fctl-On-Behalf-Of:
`, `fctl --on-behalf-of`), and the session it starts is theirs: on their Claude subscription, within their roles, followed by them. It acts only for members who allowed it, unless the instance's admins turned asking off; without a person it reads the workspace's projects, sessions and schedules, and runs schedules for the people they run for. Its admins make them; it works while the admin who made its secret is still one. @@ -237,7 +237,7 @@ Each recipe says who does what: some steps take a person with a role in the proj - [Self-hosting](https://fctl.sh/docs/self-hosting.md): the control plane in a container (Docker, Kubernetes) or on Cloudflare, settings, HTTPS, the first account, provisioning people with admin tokens, the GitHub App (each field of its form, permissions, webhook events, follow-ups), the optional review app, the Linear app (its form and webhook events), Google sign-in, email, hosts. - [Identity tokens](https://fctl.sh/docs/identity-tokens.md): OIDC tokens with which agents prove to your services and clouds that a request comes from one of your sessions: `fctl id-token`, every claim and the subject, checking a token (jose, PyJWT), AWS roles with trust policies and session tags, Google Cloud workload identity, Azure federated credentials, Vault, what a token proves. - [fctl for organizations](https://fctl.sh/docs/organizations.md): running fctl for a company: its own instance and the settings organizations change, provisioning people from a directory with admin tokens, service accounts for portals and bots that start sessions for people, access tokens and schedules for CI and other tools, webhooks to other tools with recipes, enrollment tokens for fleets of runners, audit logs, and every credential at a glance. -- [Sandbox images](https://fctl.sh/docs/sandbox-images.md): the default image and its layout, a project's own image or one built from its repository, which images a host runs, what an image needs, what fctl writes into a sandbox. +- [Sandbox images](https://fctl.sh/docs/sandbox-images.md): the default image and its layout, a project's own image or one built from its repository, an image from another base such as Ubuntu (installing fctl and Claude Code in it), which images a host runs, what an image needs, what fctl writes into a sandbox. - [Architecture](https://fctl.sh/docs/architecture.md): how every piece works and talks: identity, workspaces, sessions, GitHub, review agents, follow-ups, schedules, trackers, Linear, events, credentials, sandboxes, protocols, deployment. - [Security](https://fctl.sh/docs/security.md): what fctl protects and how, what sandboxes can reach, what tokens carry, billing guards, hosts, retention. - [Development](https://fctl.sh/docs/development.md): working on fctl itself: the local stack with fake-claude, checks, the repository map. diff --git a/docs/sandbox-images.md b/docs/sandbox-images.md index b032647d..655bbabd 100644 --- a/docs/sandbox-images.md +++ b/docs/sandbox-images.md @@ -2,8 +2,9 @@ With the Apple container and Docker drivers, each session runs in a container made from an image. This page describes the default image and -how hosts get it, how a project uses an image of its own or builds one from -its repository, which images a host runs, and what an image needs. +how hosts get it, how a project uses an image of its own (built on the +default one, or on another base such as Ubuntu) or builds one from its +repository, which images a host runs, and what an image needs. ## The default image @@ -192,9 +193,11 @@ USER agent When sessions need tools the default image lacks, such as .NET or a company's CLIs, give the project an image that has them. A setup script -would install them in every session instead. This example adds the .NET 8 -SDK. .NET needs ICU, which Debian has, and the SDK goes into `agent`'s -home, like Rust. The PATH is set twice: `ENV` for Claude and the commands +would install them in every session instead. An image you already have, +on Ubuntu say, works too once fctl and Claude Code are in it ([An image +from another base](#an-image-from-another-base)). This example adds the +.NET 8 SDK. .NET needs ICU, which Debian has, and the SDK goes into +`agent`'s home, like Rust. The PATH is set twice: `ENV` for Claude and the commands it runs, and `/etc/profile.d` for login shells, which setup scripts run in: ```dockerfile @@ -216,6 +219,12 @@ ENV DOTNET_ROOT=/home/agent/.dotnet \ PATH=/home/agent/.dotnet:/home/agent/.dotnet/tools:$PATH ``` +Of the image's variables, Claude gets the PATH and the locale but not the +others ([An image from another base](#an-image-from-another-base)): +`dotnet` finds its SDK beside itself, and for Claude's commands, +`DOTNET_ROOT` and `DOTNET_CLI_TELEMETRY_OPTOUT` go in the project's +variables too. + 1. **Build it for both architectures** and push it to a registry: Apple silicon runners run arm64 images, most others amd64. @@ -252,6 +261,130 @@ ENV DOTNET_ROOT=/home/agent/.dotnet \ Lima runners don't use images: their sessions run in a clone of the VM `fctl host image build` prepared. The process driver uses none either. +## An image from another base + +An image doesn't have to start from the default one. One your company +already has, on Ubuntu with its own toolchains say, runs sessions once it +has what fctl needs ([What an image needs](#what-an-image-needs)): fctl, +Claude Code, git, gh, bash and a user other than root. fctl-agent, the +supervisor, isn't one of them: the host copies its own into each sandbox +when it starts a session there, of the host's version, so an image has +none to install or update. + +This Dockerfile makes Ubuntu 24.04 into a sandbox image: add your packages +and steps to it, or its steps to your Dockerfile. The sandbox repository +keeps it, as +[`examples/ubuntu/Dockerfile`](https://github.com/hyperstructure/sandbox/blob/main/examples/ubuntu/Dockerfile), +and builds and checks it for both architectures. + +```dockerfile +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 +``` + +- **fctl** comes from its installer, into `/usr/local/bin` for every + user: with it, agents name their sessions, ask people, publish + screenshots and keep their project's memory. Its Linux builds are + static, so they run on any distribution, on arm64 and amd64. + `--build-arg FCTL_VERSION=0.37.0` pins a release; without it, the + latest. The archive has the Linux fctl-agent beside fctl, which the + image doesn't need. +- **Claude Code** installs as the user sessions run as, into + `~/.local/bin`, which the image's `PATH` names. +- **The user.** Sessions run as the image's `USER`, in `~/workspace`: a + user with a line in `/etc/passwd`, where fctl-agent finds its home, and a + home it can write to. Ubuntu's images from 24.04 come with the user + `ubuntu`, uid 1000, which sessions could run as too (`USER ubuntu`); the + example gives the image `agent`, as the default image has. sudo without a + password lets the agent install what a task needs. `/var/cache/fctl` is + the user's, as in the default image: projects that share package caches + mount them there ([Its layout](#its-layout)). +- **The environment.** Claude and its commands get the image's `PATH`, + `LANG`, `LC_ALL`, `TZ` and `TMPDIR`, and none of its other variables: put + tools on the PATH, and set the variables they need in the project's + Settings → Sandbox → Environment (`fctl projects set -p my-app --env + JAVA_HOME=/opt/java`). The setup script gets the image's whole + environment, in a login shell (`bash -lc`). Ubuntu's login shells keep + the image's PATH, but Debian's and Alpine's `/etc/profile` set one of + their own, so an image on those names its directories in + `/etc/profile.d` too, as the default image does: + `echo 'PATH="$HOME/.local/bin:$PATH"' > /etc/profile.d/fctl.sh`, as root. +- **What the image starts doesn't run.** fctl gives each sandbox a main + process of its own (`tail -f /dev/null` in a container, fctl-agent in a + Firecracker VM) in place of the image's `ENTRYPOINT` and `CMD`: a + database or another service the image would start, the project's setup + script starts instead. +- **Keep it current.** fctl turns off Claude Code's auto-updater, so the + image's Claude Code is as old as the image, and agents reach fctl's new + features through the image's fctl. fctl tells agents only of the + commands it has: the session's log says when it lacks those that rename + the session, keep the project's memory, reach its tickets or run an + autopilot or a review agent, and others, like asking people or + publishing screenshots, the agent goes without. Build the image again + for fctl's releases, with `--no-cache` or a new `FCTL_VERSION`, since + Docker would otherwise reuse the steps that installed them; the default + image is also rebuilt on each day Claude Code has a new release. +- **Other distributions** take the same steps with their own packages. On + Alpine: `apk add bash ca-certificates curl git github-cli sudo shadow` + (Claude Code needs bash, and `shadow` has `useradd`), and the PATH in + `/etc/profile.d`. + +The sandbox repository's +[`examples/check.sh`](https://github.com/hyperstructure/sandbox/blob/main/examples/check.sh) +checks an image for what fctl needs: it runs in the image as its user, in +place of the image's `ENTRYPOINT` as in a session, and says what's +missing. + +```sh +curl -fsSL https://raw.githubusercontent.com/hyperstructure/sandbox/main/examples/check.sh -o check.sh +docker run --rm -i --entrypoint sh my-sandbox -s < check.sh +``` + +Then build the image for both architectures, push it and choose it for +the project, as [Your own image](#your-own-image) describes. + ## Building it from the repository A project can build its image from a Dockerfile or a dev container @@ -325,9 +458,10 @@ Dockerfile with `USER vscode`, say, to run as that user. Docker Compose configurations aren't built. The image still needs what every image needs ([below](#what-an-image-needs)): -most dev container images lack Claude Code. Start the Dockerfile `FROM -ghcr.io/hyperstructure/sandbox:0.14`, or install Claude Code in it as the -user sessions run as (`curl -fsSL https://claude.ai/install.sh | bash`). +most dev container images lack Claude Code and fctl. Start the Dockerfile +`FROM ghcr.io/hyperstructure/sandbox:0.14`, or install them in it as [An +image from another base](#an-image-from-another-base) does: fctl for every +user, and Claude Code as the user sessions run as. ## Which images a host runs @@ -383,10 +517,20 @@ show each runner's image and lists. ## What an image needs -An image that doesn't start from the default one needs: - -- **`sh`, `tail`, `id` and git** on the PATH. The sandbox's main process - is `tail -f /dev/null`, and `id -u` tells fctl who the image's user is. +An image that doesn't start from the default one needs what follows +([An image from another base](#an-image-from-another-base) builds one on +Ubuntu, and the sandbox repository's `examples/check.sh` checks an image +for it). It needs no fctl-agent: the host copies its own in ([What fctl +writes into a sandbox](#what-fctl-writes-into-a-sandbox)). + +- **`/bin/sh`, `tail`, `id`, `cat`, `mkdir`, `chown`, `chmod`, `mv`, `rm` + and `stat`** in `/usr/bin` or `/bin`, where the host runs them in the + sandbox. A container's main process is `tail -f /dev/null`, in place of + the image's `ENTRYPOINT` and `CMD`, and `id -u` tells fctl who the + image's user is. +- **git**, with CA certificates for HTTPS, on the PATH: fctl-agent clones + the project's repositories with it. +- **bash**, which runs the project's setup script, in a login shell. - **Claude Code 2.1.101 or later**, as `claude` on the PATH. fctl relies on requests that Claude Code sends and answers in its stream-json mode: it asks fctl for a fresh OAuth access token (`oauth_token_refresh`, from @@ -402,11 +546,13 @@ An image that doesn't start from the default one needs: update their retrospectives where it has `fctl retro update`, and record one for each follow-up where it doesn't). Without it, sessions keep the title they start with, and their agents keep no memory. -- **A non-root user with a writable home.** fctl copies its supervisor into - `/opt/fctl/bin` as root at session start, gives the directory to root, - and runs the supervisor as root, and Claude and its commands as the - image's user (its `USER`), in `~/workspace`. An image that runs as root - runs Claude as root, whose commands can stop fctl-agent. +- **A non-root user with a writable home**, and a line in `/etc/passwd`, + where fctl-agent finds its home (without one, its home is `/`). fctl + copies its supervisor into `/opt/fctl/bin` as root at session start, + gives the directory to root, and runs the supervisor as root, and Claude + and its commands as the image's user (its `USER`), in `~/workspace`. An + image that runs as root runs Claude as root, whose commands can stop + fctl-agent. - **arm64** builds for Apple silicon runners, and amd64 for most others. ## What fctl writes into a sandbox