Files
davidandClaude Opus 5.5 b609252e1c Pin srt to a tested version; support only Pop!_OS 26.04 and later
srt is pinned to 0.0.83, the version the smoketest passed with. A computer
with another version sees the agents item as to do in configure, which
installs the pinned one. Move the pin only after smoketest/run 50 80 passes.

The installer and configure stop on Pop!_OS (or Ubuntu) older than 26.04.
The smoketest builds on Ubuntu 26.04, with checks that 24.04 is refused.
26.04's own AppArmor profile lets bubblewrap make user namespaces, so the
connector's profile for it, and the code that offered to add it, are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 20:49:54 -07:00

100 lines
4.0 KiB
Bash

#!/bin/bash
#
# Purpose : Node.js and Anthropic's sandbox runtime (srt) for the agent
# sandbox. Source this file after lib/agents.sh; it uses
# confirm_yes from configure.
#
# srt needs Node.js 22.12 or later, which Pop!_OS doesn't install. So unless
# one is installed already (Pop!_OS 26.04's nodejs package is new enough), the
# current long-term support release is downloaded from nodejs.org into
# FC_TOOLS/node, checked against the SHA-256 sums it publishes, and used only
# for srt: nothing in /usr or your shell changes.
#
# srt is pinned to a version the smoketest passed with: a new release once
# broke opencode's sandbox on Pop!_OS. To move the pin, change SRT_VERSION,
# run smoketest/run 50 80, and commit only if it passes. Computers that have
# the old version see the agents item as to do in configure, which installs
# the new one.
SRT_VERSION=0.0.83
# srt needs Node.js 22.12 or later
node_ok() {
local node version
node="$(PATH="$FC_TOOLS/node/bin:$PATH" command -v node)" || return 1
version="$("$node" -p 'process.versions.node' 2> /dev/null)" || return 1
[ "$(printf '%s\n' 22.12.0 "$version" | sort -V | head -n 1)" = 22.12.0 ]
}
# download_checked <url> <sums url> <file name in sums> <destination>
download_checked() {
local url="$1" sums_url="$2" name="$3" dest="$4" expected actual
echo "Downloading $url"
curl -fL --progress-bar --max-time 1800 -o "$dest" "$url" || return 1
expected="$(curl -fsL --max-time 30 "$sums_url" | awk -v f="$name" '$2 == f || $2 == "*" f { print $1; exit }')"
actual="$(sha256sum "$dest" | cut -d' ' -f1)"
if [ -z "$expected" ] || [ "$expected" != "$actual" ]; then
echo -e "\e[31mThe download doesn't match the checksum its release publishes. Not installing it.\e[0m"
rm -f "$dest"
return 1
fi
}
install_node() {
local tmp version arch name status=1
version="$(curl -fsL --max-time 30 https://nodejs.org/dist/index.json \
| jq -r '[.[] | select(.lts)][0].version // empty')"
[ -n "$version" ] || { echo "Couldn't find Node.js' current release."; return 1; }
case "$(uname -m)" in
aarch64|arm64) arch=arm64 ;;
*) arch=x64 ;;
esac
name="node-$version-linux-$arch.tar.xz"
tmp="$(mktemp -d)" || return 1
if download_checked "https://nodejs.org/dist/$version/$name" \
"https://nodejs.org/dist/$version/SHASUMS256.txt" "$name" "$tmp/$name" \
&& tar -xJf "$tmp/$name" -C "$tmp" && mkdir -p "$FC_TOOLS"; then
rm -rf "$FC_TOOLS/node" && mv "$tmp/${name%.tar.xz}" "$FC_TOOLS/node" && status=0
fi
rm -rf "$tmp"
return $status
}
# srt from npm, into FC_TOOLS/srt. It has no install scripts of its own; the
# ones npm would warn it blocked belong to a Windows-only package it
# optionally depends on.
install_srt() {
local node_dir
node_ok || install_node || return 1
node_dir="$(dirname "$(PATH="$FC_TOOLS/node/bin:$PATH" command -v node)")"
echo "Installing the sandbox runtime (srt) from npm..."
PATH="$node_dir:$PATH" "$node_dir/npm" install --global --prefix "$FC_TOOLS/srt" \
--no-fund --no-audit --ignore-scripts "@anthropic-ai/sandbox-runtime@$SRT_VERSION" > /dev/null
}
# The version of Federated Connector's own srt, or nothing
srt_version() {
jq -r '.version // empty' \
"$FC_TOOLS/srt/lib/node_modules/@anthropic-ai/sandbox-runtime/package.json" 2> /dev/null
}
# Federated Connector's own srt is installed, at the version it's pinned to
srt_current() {
[ "$(srt_version)" = "$SRT_VERSION" ] && srt_path > /dev/null
}
# Updating srt is installing it again
srt_ensure() {
srt_current && return 0
if [ -n "$(srt_version)" ]; then
echo "The sandbox runtime (srt) is at $(srt_version); this version of Federated Connector"
echo "was tested with $SRT_VERSION."
confirm_yes "Install $SRT_VERSION?" || return 1
install_srt
return
fi
echo "The sandbox is Anthropic's sandbox runtime (srt), which runs on Node.js."
node_ok || echo "This computer's Node.js is older than srt needs, so it gets its own, from nodejs.org."
confirm_yes "Install it (into $FC_TOOLS)?" || return 1
install_srt
}