Skip to content

Commit 50cd637

Browse files
fctl-sh[bot]claude
andauthored
feat: add Python 3.15, Rust, Bun and TypeScript to the sandbox image (#45)
The default sandbox image had Node.js, Debian's Python 3.11 and little else, so sessions installed toolchains before they could build anything; #16 notes that a session working on fctl installs rustup and builds from cold. `images/agent/provision.sh` now installs, at versions set at its top: - **Python 3.15.0** as `python3` and `python` for every user: uv's build of CPython in `/opt/uv/python`, linked from `/usr/local/bin`. **uv** is pinned to 0.13.1. - **Rust 1.99.0** through rustup, with rustfmt, Clippy and `wasm32-unknown-unknown`: the toolchain `rust-toolchain.toml` pins, so sessions working on fctl download nothing. A new test in `crates/fctl-host/src/image.rs` fails when the two drift apart. - **TypeScript 7.0.2** (`tsc`) and **Bun 1.4.3** beside Node.js 22. - cmake, OpenSSL's headers, wget, rsync, lsof, psmisc (`fuser`, `killall`), zstd, ShellCheck and sqlite3, and `fd` as a link to Debian's `fdfind`. Decisions: - **Rust and Bun live in the agent's home** (`~/.rustup`, `~/.cargo`, `~/.bun`). fctl-agent starts Claude with only PATH, HOME, the locale and a few login variables (`crates/fctl-agent/src/claude.rs`), so a system-wide rustup, which needs `RUSTUP_HOME`, would not work in Claude's shell. In the home, both work from HOME and PATH alone, and agents add toolchains, targets and global tools without sudo. - **Python is system-wide**, so root and images built `FROM` this one (#39) get the same interpreter, with venv and pip. Debian's `python3-pip` and `python3-venv` go; its `python3` stays, behind `/usr/local/bin` on the PATH, because NodeSource's `nodejs` depends on it. - **One PATH.** The Dockerfile's `ENV PATH` gains `~/.cargo/bin` and `~/.bun/bin`, and `/etc/profile.d/fctl.sh` sets the same for login shells: setup scripts run with `bash -lc`, and `limactl shell` runs the Lima driver's commands in one. It replaces the `~/.profile` line, which was never written: its guard grepped for `.local/bin`, which Debian's skeleton `.profile` already contains, so login shells lost `/opt/fctl/bin`. - **npm** leaves out its funding and audit notices and its update check (`/usr/etc/npmrc`), which only lengthened agents' output; `npm audit` still works. CI already runs `npm ci --no-audit --no-fund`. - **Left out:** git-lfs, because Debian's package turns on LFS downloads for every clone, which would change how sessions clone LFS repositories and spend their LFS bandwidth; Go, Java and the like, for the image's size. Node.js stays at 22, as in CI. The image grows by about 0.9 GB uncompressed on arm64: Rust 640 MB, Python 96 MB, Bun 85 MB, TypeScript 30 MB and about 100 MB of Debian packages (ShellCheck alone is 41 MB). ## Verification - `provision.sh` ran end to end on this session's sandbox (Debian bookworm, arm64) for a fresh user, three times as it changed. Its last step prints every tool's version from the agent's login shell: Claude Code 2.1.302, fctl 0.2.0, Python 3.15.0, uv 0.13.1, rustc and cargo 1.99.0, Node.js 22.23.3, tsc 7.0.2 and Bun 1.4.3. - As that user, with only HOME and the Dockerfile's PATH, as fctl-agent starts Claude: `python3 -m venv` with pip, a C extension built from source, `uv venv`, `uv pip install` and `uv run --with`; `cargo run`, a `wasm32-unknown-unknown` build, `cargo fmt`, `cargo clippy` and a crate that links OpenSSL; `tsc` and Bun compiling and running TypeScript; `npm install` without funding or audit lines; binaries from `bun add -g` and `uv tool install` found on the PATH; and every CLI tool above. With this repository's `rust-toolchain.toml`, rustup selects the installed 1.99.0 and downloads nothing. - `cargo xtask check` passes. The new test fails, saying what to change, when `RUST_VERSION` or a target differs from `rust-toolchain.toml`. - ShellCheck is clean on `provision.sh`. - Not done: a `docker build` (this sandbox has no container runtime) and amd64. #39's Image workflow builds the image for both architectures and runs `check.sh` on pull requests that change `images/agent`, so it covers this change once either pull request is on main. ## Overlap with #39 #39 also edits the Dockerfile's header comment, `images/agent/README.md`, `docs/architecture.md` and `docs/getting-started.md`; `provision.sh` merges cleanly. Whichever lands second keeps both sides' facts. With both in, `docs/sandbox-images.md` should list these tools and the PATH (`~/.local/bin`, `~/.cargo/bin`, `~/.bun/bin`, `/opt/fctl/bin`), and `check.sh` could check for `cargo`, `tsc` and `bun`. Refs #16 Session: https://app.fctl.sh/s/ses_01M56D7AEK3XQYQJH6TQXYMDZ5 --------- Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 3b70a94 commit 50cd637

6 files changed

Lines changed: 134 additions & 23 deletions

File tree

‎crates/fctl-host/src/image.rs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ async fn run_inherit(program: &str, args: &[&str]) -> Result<()> {
135135

136136
#[cfg(test)]
137137
mod tests {
138-
use super::shell_quote;
138+
use super::{PROVISION, shell_quote};
139139

140140
#[test]
141141
fn quotes_values_for_sh() {
@@ -145,4 +145,37 @@ mod tests {
145145
);
146146
assert_eq!(shell_quote("it's"), "'it'\\''s'");
147147
}
148+
149+
/// Sessions working on fctl find its toolchain already installed, rather
150+
/// than having rustup download a second one.
151+
#[test]
152+
fn installs_the_rust_this_repository_builds_with() -> anyhow::Result<()> {
153+
#[derive(serde::Deserialize)]
154+
struct File {
155+
toolchain: Toolchain,
156+
}
157+
#[derive(serde::Deserialize)]
158+
struct Toolchain {
159+
channel: String,
160+
#[serde(default)]
161+
components: Vec<String>,
162+
#[serde(default)]
163+
targets: Vec<String>,
164+
}
165+
let File { toolchain } = toml::from_str(include_str!("../../../rust-toolchain.toml"))?;
166+
let mut wanted = vec![format!("RUST_VERSION:-{}}}", toolchain.channel)];
167+
if !toolchain.components.is_empty() {
168+
wanted.push(format!("--component {}", toolchain.components.join(",")));
169+
}
170+
if !toolchain.targets.is_empty() {
171+
wanted.push(format!("--target {}", toolchain.targets.join(",")));
172+
}
173+
for w in wanted {
174+
assert!(
175+
PROVISION.contains(&w),
176+
"images/agent/provision.sh should have `{w}`, as rust-toolchain.toml says"
177+
);
178+
}
179+
Ok(())
180+
}
148181
}

‎docs/architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ before changing anything that crosses a component boundary.
4242
| `crates/fake-claude` | A scripted stand-in for `claude` that speaks stream-json. Used by tests and `cargo xtask dev`. | dev, CI |
4343
| `xtask` | Development automation (`cargo xtask dev`, `check`, `gen`, `deploy`, `dist`, `publish`). | dev, CI |
4444
| `web/` | The web app (React, Vite, TypeScript, WebGL), installable on phones and computers. Served by fctl-control. | browser |
45-
| `images/agent` | The default sandbox image (Debian, git, gh, node, python, claude, fctl). | sandboxes |
45+
| `images/agent` | The default sandbox image (Debian, git, gh, Python, Rust, Node.js, Bun, claude, fctl). | sandboxes |
4646

4747
Two more repositories complete the picture:
4848
[hyperstructure/design](https://github.com/hyperstructure/design)

‎docs/getting-started.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ Any Mac with Apple silicon (or a Linux box) can be a host. On the Mac:
7878
fctl host install --build-image
7979
```
8080

81-
This builds the sandbox image (Debian with git, gh, Node, Python, uv and
82-
Claude Code), writes `~/.config/fctl/host.toml`, and installs a launchd
83-
agent (`sh.fctl.host`) that starts at login, restarts if it stops, and
84-
keeps the Mac from sleeping while it is plugged in, so it can start work
85-
at any hour.
81+
This builds the sandbox image (Debian with git, gh, Python, uv, Rust,
82+
Node, TypeScript, Bun and Claude Code), writes
83+
`~/.config/fctl/host.toml`, and installs a launchd agent (`sh.fctl.host`)
84+
that starts at login, restarts if it stops, and keeps the Mac from
85+
sleeping while it is plugged in, so it can start work at any hour.
8686

8787
3. Check it:
8888

‎images/agent/Dockerfile‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# The default fctl sandbox image: Debian with git, gh, Node.js, Python (uv),
2-
# build tools, Claude Code and fctl. Sessions run as the `agent` user.
1+
# The default fctl sandbox image: Debian with git, gh, build tools, Python and
2+
# uv, Rust, Node.js, TypeScript, Bun, Claude Code and fctl (README.md lists
3+
# the versions). Sessions run as the `agent` user.
34
#
45
# fctl host image build # builds it with your driver (apple or docker)
56
# docker build -t fctl-agent:latest images/agent
@@ -16,5 +17,6 @@ RUN bash /tmp/provision.sh && rm /tmp/provision.sh
1617

1718
USER agent
1819
WORKDIR /home/agent
19-
ENV PATH=/home/agent/.local/bin:/opt/fctl/bin:$PATH
20+
# As /etc/profile.d/fctl.sh (provision.sh) sets it for login shells.
21+
ENV PATH=/home/agent/.local/bin:/home/agent/.cargo/bin:/home/agent/.bun/bin:/opt/fctl/bin:$PATH
2022
CMD ["tail", "-f", "/dev/null"]

‎images/agent/README.md‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
# Agent image
22

3-
The default sandbox for fctl sessions: Debian bookworm with git, the GitHub
4-
CLI, Node.js 22, Python 3 with uv, build tools, ripgrep, Claude Code
5-
(installed for the `agent` user, who has passwordless sudo: the sandbox is
6-
the boundary) and fctl (in `/usr/local/bin`).
3+
The default sandbox for fctl sessions: Debian bookworm with the toolchains
4+
agents build and test with, Claude Code (installed for the `agent` user, who
5+
has passwordless sudo: the sandbox is the boundary) and fctl (in
6+
`/usr/local/bin`).
77

8+
- Python 3.15.0 as `python3` and `python` for every user (uv's build of
9+
CPython, in `/opt/uv/python`), and uv 0.13.1.
10+
- Rust 1.99.0 through rustup, with rustfmt, Clippy and the
11+
`wasm32-unknown-unknown` target: the toolchain in this repository's
12+
`rust-toolchain.toml`, so sessions working on fctl have nothing to
13+
download.
14+
- Node.js 22 with npm, TypeScript 7.0.2 (`tsc`) and Bun 1.4.3.
15+
- build-essential (gcc, make), cmake, pkg-config and OpenSSL's headers.
16+
- git, the GitHub CLI, ripgrep, fd, jq, ShellCheck, sqlite3, curl, wget,
17+
rsync, lsof, fuser, tree, file, zip, xz and zstd.
18+
19+
The versions are set at the top of `provision.sh`. A test in
20+
`crates/fctl-host/src/image.rs` fails when Rust's differs from
21+
`rust-toolchain.toml`.
22+
23+
- Rust and Bun are installed for the agent user (in `~/.rustup` and
24+
`~/.cargo`, and `~/.bun`), so agents add toolchains, targets and global
25+
tools without sudo: `cargo install`, `bun add -g`, and for Python `uv
26+
tool install` and `uv python install`. Images built from this one run
27+
cargo as `agent`.
28+
- Python is marked externally managed: packages go into a virtual
29+
environment (`uv venv`, `python3 -m venv`) or come with `uv run --with`.
30+
Debian's Python 3.11, which Node.js depends on, stays in `/usr/bin`,
31+
after `/usr/local/bin` on the PATH.
32+
- `~/.local/bin`, `~/.cargo/bin`, `~/.bun/bin` and `/opt/fctl/bin` lead the
33+
PATH. The Dockerfile sets it, and `/etc/profile.d/fctl.sh` sets it for
34+
login shells (setup scripts, the Lima VM). fctl-agent passes Claude the
35+
PATH, HOME and locale but not the image's other environment variables, so
36+
every tool here works from the PATH alone.
37+
- npm leaves out its funding and audit notices and its update check
38+
(`/usr/etc/npmrc`); `npm audit` still runs when asked.
839
- `fctl host image build` builds it locally as `fctl-agent:latest` with the
940
host's driver (Apple `container build` or `docker build`), or provisions
1041
the `fctl-base` Lima VM with the same `provision.sh`. It installs the

‎images/agent/provision.sh‎

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
# shellcheck disable=SC2016 # single-quoted scripts expand in the agent's shell
23
# Provisions an fctl agent sandbox: the tools agents need, Claude Code and
34
# fctl. Used by the Dockerfile (container sandboxes) and by `fctl host image
45
# build --driver lima` (the fctl-base VM). Runs as root.
@@ -9,29 +10,47 @@
910
set -euo pipefail
1011

1112
AGENT_USER="${AGENT_USER:-agent}"
13+
# Toolchain versions. Rust is the release this repository builds with
14+
# (rust-toolchain.toml; a test in crates/fctl-host/src/image.rs keeps the two
15+
# in step), so sessions working on fctl have nothing to download.
1216
NODE_MAJOR="${NODE_MAJOR:-22}"
17+
TYPESCRIPT_VERSION="${TYPESCRIPT_VERSION:-7.0.2}"
18+
BUN_VERSION="${BUN_VERSION:-1.4.3}"
19+
UV_VERSION="${UV_VERSION:-0.13.1}"
20+
PYTHON_VERSION="${PYTHON_VERSION:-3.15.0}"
21+
RUST_VERSION="${RUST_VERSION:-1.99.0}"
1322
FCTL_VERSION="${FCTL_VERSION:-}"
1423
FCTL_DOWNLOAD="${FCTL_DOWNLOAD:-}"
1524
export DEBIAN_FRONTEND=noninteractive
1625

1726
apt-get update
1827
apt-get install -y --no-install-recommends \
19-
ca-certificates curl git gnupg less openssh-client procps sudo unzip xz-utils zip \
20-
build-essential pkg-config jq ripgrep fd-find tree file \
21-
python3 python3-venv python3-pip
28+
ca-certificates curl wget git gnupg less openssh-client procps psmisc lsof sudo \
29+
rsync unzip xz-utils zip zstd \
30+
build-essential cmake pkg-config libssl-dev \
31+
jq ripgrep fd-find tree file shellcheck sqlite3
32+
# Debian calls fd `fdfind`.
33+
ln -sf /usr/bin/fdfind /usr/local/bin/fd
2234

2335
# GitHub CLI
2436
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /usr/share/keyrings/githubcli-archive-keyring.gpg
2537
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
2638
> /etc/apt/sources.list.d/github-cli.list
2739

28-
# Node.js
40+
# Node.js and TypeScript. npm leaves out its funding and audit notices and
41+
# its update check, which only lengthen agents' output.
2942
curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | bash -
3043
apt-get install -y --no-install-recommends gh nodejs
3144
corepack enable || true
45+
npm config set --location=global fund=false audit=false update-notifier=false
46+
npm install -g "typescript@$TYPESCRIPT_VERSION"
47+
npm cache clean --force
3248

33-
# uv (Python)
34-
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
49+
# uv, and Python for everyone: uv's build of CPython in /opt/uv/python, as
50+
# python3 and python in /usr/local/bin.
51+
curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh
52+
env UV_PYTHON_INSTALL_DIR=/opt/uv/python UV_PYTHON_BIN_DIR=/usr/local/bin UV_NO_CACHE=1 \
53+
uv python install --default --preview-features python-install-default "$PYTHON_VERSION"
3554

3655
rm -rf /var/lib/apt/lists/*
3756

@@ -64,6 +83,32 @@ rm -f /usr/local/bin/fctl-agent-*-linux
6483
AGENT_HOME="$(getent passwd "$AGENT_USER" | cut -d: -f6)"
6584
sudo -u "$AGENT_USER" -H bash -c 'curl -fsSL https://claude.ai/install.sh | bash'
6685
sudo -u "$AGENT_USER" -H mkdir -p "$AGENT_HOME/workspace"
67-
grep -q '.local/bin' "$AGENT_HOME/.profile" 2>/dev/null || echo 'export PATH="$HOME/.local/bin:/opt/fctl/bin:$PATH"' >> "$AGENT_HOME/.profile"
68-
"$AGENT_HOME/.local/bin/claude" --version
69-
/usr/local/bin/fctl --version
86+
87+
# The agent's PATH: Claude Code and uv's tools in ~/.local/bin, Rust's and
88+
# Bun's tools, then fctl's supervisor. The Dockerfile sets the same; login
89+
# shells (setup scripts, the Lima driver's) get it from here.
90+
cat > /etc/profile.d/fctl.sh <<'EOF'
91+
PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.bun/bin:/opt/fctl/bin:$PATH"
92+
EOF
93+
94+
# Runs a script as the agent user in a login shell; it gets the arguments
95+
# after the script as $1….
96+
as_agent() {
97+
local script="$1"
98+
shift
99+
sudo -u "$AGENT_USER" -H bash -lc "set -euo pipefail; $script" bash "$@"
100+
}
101+
102+
# Rust, with the components and targets that rust-toolchain.toml lists, and
103+
# Bun, in the agent's home: they find their files through HOME alone
104+
# (fctl-agent passes Claude no RUSTUP_HOME or the like), and agents add
105+
# toolchains, targets and global tools without sudo.
106+
as_agent 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs |
107+
sh -s -- -y --no-modify-path --profile minimal --default-toolchain "$1" \
108+
--component rustfmt,clippy --target wasm32-unknown-unknown' "$RUST_VERSION"
109+
as_agent 'curl -fsSL https://bun.sh/install | bash -s "bun-v$1"' "$BUN_VERSION"
110+
as_agent 'ln -sf bun "$HOME/.bun/bin/bunx"'
111+
112+
# What sessions find on the PATH.
113+
as_agent 'claude --version; fctl --version; python3 --version; uv --version
114+
rustc --version; cargo --version; node --version; tsc --version; bun --version'

0 commit comments

Comments
 (0)