feat(sandbox): podman backend + goose AI harness + noVNC GUI sandbox

Add Podman as a rootless/daemonless sandbox backend alongside Docker,
Multipass and Local, and wire Goose in as the default agentic harness
for the granted `!task` path (bridge execs `<engine> exec <name> goose
run` and streams output to chat; auto-degrades to the simple one-shot
injector when goose is absent).

Add an optional GUI sandbox track (XFCE + TigerVNC + websockify/noVNC on
:6080) summoned via `/sbx <engine> gui`, plus container-side provisioning
in sandbox-bootstrap.sh and a host-side ensure-podman.sh prereq helper.

Refresh the in-app command help to the backend-led `/sbx <engine> [gui]`
grammar and minor ui tweaks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
leetcrypt
2026-06-08 10:38:18 -07:00
parent eec1714735
commit 20091a9c26
9 changed files with 929 additions and 143 deletions
+73 -6
View File
@@ -8,12 +8,18 @@
#
# The baseline is untouched: ./bootstrap.sh alone never installs or enables AI.
#
# It also installs Goose (block/goose) by default — the agentic harness the /ai
# agent uses for the sandbox `!task` path — and writes a host Goose config that
# points it at the local Ollama. Skip it with --no-goose (the agent still works:
# the bridge falls back to its built-in one-shot injector).
#
# usage:
# ./bootstrap-ai.sh # baseline setup + Ollama + default model
# ./bootstrap-ai.sh # baseline setup + Ollama + default model + Goose
# ./bootstrap-ai.sh --release # ...and build the client in release mode
# ./bootstrap-ai.sh --check # report only; install/pull nothing
# ./bootstrap-ai.sh --yes # don't prompt before installing Ollama / pulling the model
# ./bootstrap-ai.sh --ai-only # only the AI layer; skip the baseline ./bootstrap.sh
# ./bootstrap-ai.sh --no-goose # skip the Goose harness install (one-shot injector only)
# ./bootstrap-ai.sh -h | --help # this help
#
# environment:
@@ -25,19 +31,22 @@ ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
MODEL="${HH_AI_MODEL:-qwen2.5:3b}"
OLLAMA_HOST="${OLLAMA_HOST:-http://localhost:11434}"
INSTALLER_URL="https://ollama.com/install.sh"
GOOSE_INSTALLER_URL="https://github.com/block/goose/releases/download/stable/download_cli.sh"
RELEASE_ARGS=()
CHECK_ONLY=0
ASSUME_YES=0
AI_ONLY=0
DO_GOOSE=1
for arg in "$@"; do
case "$arg" in
--release) RELEASE_ARGS+=(--release) ;;
--check) CHECK_ONLY=1 ;;
--yes|-y) ASSUME_YES=1 ;;
--ai-only) AI_ONLY=1 ;;
--release) RELEASE_ARGS+=(--release) ;;
--check) CHECK_ONLY=1 ;;
--yes|-y) ASSUME_YES=1 ;;
--ai-only) AI_ONLY=1 ;;
--no-goose) DO_GOOSE=0 ;;
-h|--help|-help) grep '^#' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) echo "✖ unknown arg: $arg (try --release / --check / --yes / --ai-only / --help)" >&2; exit 2 ;;
*) echo "✖ unknown arg: $arg (try --release / --check / --yes / --ai-only / --no-goose / --help)" >&2; exit 2 ;;
esac
done
@@ -65,6 +74,14 @@ if have ollama; then echo " ✓ ollama ($(ollama --version 2>&1 | head -1))"
else echo " · ollama not installed"; fi
if ollama_up; then echo " ✓ ollama daemon reachable at $OLLAMA_HOST"
else echo " · ollama daemon not reachable at $OLLAMA_HOST"; fi
# Goose may install to ~/.local/bin, which isn't always on PATH in this shell.
goose_bin() { command -v goose 2>/dev/null || { [[ -x "$HOME/.local/bin/goose" ]] && echo "$HOME/.local/bin/goose"; }; }
if [[ $DO_GOOSE -eq 1 ]]; then
if [[ -n "$(goose_bin)" ]]; then echo " ✓ goose ($("$(goose_bin)" --version 2>&1 | head -1))"
else echo " · goose not installed (will install — the agent's default !task harness)"; fi
else
echo " · goose skipped (--no-goose; agent uses its one-shot injector)"
fi
if [[ $CHECK_ONLY -eq 1 ]]; then
echo "--check: no changes made"
@@ -126,6 +143,56 @@ else
echo " ✓ model '$MODEL' ready"
fi
# 5. Goose harness (default on; --no-goose skips). Goose is the agentic harness
# the /ai agent runs for the sandbox `!task` path. It ships as a release binary
# (not apt/pip), so we use its official installer with CONFIGURE=false to skip
# the interactive setup — we write a minimal host config ourselves instead.
# Failure here is non-fatal: the bridge falls back to its built-in one-shot
# injector, so the agent still works without Goose.
if [[ $DO_GOOSE -eq 1 ]]; then
echo
echo "── Goose harness ──"
if [[ -z "$(goose_bin)" ]]; then
if [[ "$(uname -s)" != "Linux" && "$(uname -s)" != "Darwin" ]]; then
echo " ✖ automatic Goose install supports Linux/macOS only — see https://block.github.io/goose/ ; the agent will use its one-shot injector." >&2
else
echo " Goose is not installed. The official installer will run:"
echo " curl -fsSL $GOOSE_INSTALLER_URL | CONFIGURE=false bash"
proceed=1
if [[ $ASSUME_YES -ne 1 && -t 0 ]]; then
read -r -p " install Goose now? [Y/n] " ans
[[ -z "$ans" || "$ans" == [yY]* ]] || proceed=0
fi
if [[ $proceed -eq 1 ]]; then
if curl -fsSL "$GOOSE_INSTALLER_URL" | CONFIGURE=false bash; then
echo " ✓ goose installed ($([ -n "$(goose_bin)" ] && "$(goose_bin)" --version 2>&1 | head -1))"
else
echo " ⚠ Goose install failed — the agent will fall back to its one-shot injector" >&2
fi
else
echo " · skipped Goose install — the agent will use its one-shot injector"
fi
fi
fi
# Write a minimal host Goose config pointing at the local Ollama. Goose reads
# ~/.config/goose/config.yaml; we only set it if absent so we never clobber a
# config the user has tuned themselves.
GOOSE_CFG="${XDG_CONFIG_HOME:-$HOME/.config}/goose/config.yaml"
if [[ -f "$GOOSE_CFG" ]]; then
echo " ✓ host Goose config already exists ($GOOSE_CFG) — leaving it untouched"
else
mkdir -p "$(dirname "$GOOSE_CFG")"
cat > "$GOOSE_CFG" <<EOF
# Written by hh bootstrap-ai.sh — local-first Goose defaults (host).
GOOSE_PROVIDER: ollama
GOOSE_MODEL: $MODEL
OLLAMA_HOST: $OLLAMA_HOST
EOF
echo " ✓ wrote host Goose config → $GOOSE_CFG (ollama/$MODEL)"
fi
echo " ⓘ in-sandbox Goose (containers/VMs) is installed separately by scripts/sandbox-bootstrap.sh"
fi
echo
echo "AI ready. start a local agent against a running room with:"
echo " .venv/bin/python -m cmd_chat.agent <host> <port> \\"
+1 -1
View File
@@ -49,7 +49,7 @@ for bin in python3 cargo; do
if have "$bin"; then echo "$bin ($($bin --version 2>&1 | head -1))"
else echo "$bin — REQUIRED"; missing=1; fi
done
for bin in tmux docker multipass direnv; do
for bin in tmux docker podman multipass direnv goose; do
if have "$bin"; then echo "$bin (optional)"
else echo " · $bin not found (optional)"; fi
done
+132
View File
@@ -0,0 +1,132 @@
#!/usr/bin/env bash
# ensure-podman.sh — make sure Podman is installed before /sbx launch podman.
#
# Detect-first, never silent: if Podman is already present this exits 0 and
# changes nothing. If it's missing it prints the EXACT command it would run and
# only installs with explicit consent (--yes). --plan shows a real, no-change
# plan so you can see what would be fetched.
#
# Podman is daemonless and rootless, so unlike Docker there's no daemon to start
# and no service to enable. The one rootless prerequisite is a subuid/subgid
# range for the current user (so the container can map a user namespace); this
# script checks for it and prints how to add one if it's missing, but never edits
# those files for you (they're security-sensitive and usually pre-seeded).
#
# usage:
# ./ensure-podman.sh # interactive: prompt before installing
# ./ensure-podman.sh --yes # install without prompting
# ./ensure-podman.sh --check # test only; exit 0 if present, 1 if missing
# ./ensure-podman.sh --plan # show the install plan; change nothing
set -uo pipefail
ASSUME_YES=0
CHECK_ONLY=0
PLAN_ONLY=0
for arg in "$@"; do
case "$arg" in
-y|--yes) ASSUME_YES=1 ;;
--check) CHECK_ONLY=1 ;;
--plan|--dry-run) PLAN_ONLY=1 ;;
-h|--help) grep '^#' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) echo "✖ unknown arg: $arg" >&2; exit 2 ;;
esac
done
installed() { command -v podman >/dev/null 2>&1 && podman --version >/dev/null 2>&1; }
pm_version() { podman --version 2>/dev/null | head -1; }
# Warn (don't fix) if the current user has no subuid/subgid range — rootless
# Podman needs one to map a user namespace. Most distros seed it on user
# creation; if it's absent the user adds it once with usermod.
check_rootless_preflight() {
local u="${USER:-$(id -un)}"
if ! grep -q "^${u}:" /etc/subuid 2>/dev/null || ! grep -q "^${u}:" /etc/subgid 2>/dev/null; then
echo "ⓘ rootless preflight: no subuid/subgid range for '$u'." >&2
echo " add one once with: sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 $u" >&2
fi
}
# Already present: report, run the preflight, and stop (idempotent). --plan still
# prints the plan.
if installed; then
if [[ $PLAN_ONLY -ne 1 ]]; then
if [[ $CHECK_ONLY -ne 1 ]]; then
echo "Podman already installed ($(pm_version)) — nothing to do" >&2
check_rootless_preflight
fi
exit 0
fi
fi
[[ $CHECK_ONLY -eq 1 ]] && exit 1
# Work out how to install on this platform, and the matching no-change plan cmd.
install_cmd=""
plan_cmd=""
need_sudo=0
manual_note=""
case "$(uname -s)" in
Linux)
if command -v apt-get >/dev/null 2>&1; then
install_cmd="apt-get update && apt-get install -y podman"
plan_cmd="apt-cache policy podman"
need_sudo=1
elif command -v dnf >/dev/null 2>&1; then
install_cmd="dnf install -y podman"
plan_cmd="dnf info podman"
need_sudo=1
elif command -v pacman >/dev/null 2>&1; then
install_cmd="pacman -S --noconfirm podman"
plan_cmd="pacman -Si podman"
need_sudo=1
fi
;;
Darwin)
if command -v brew >/dev/null 2>&1; then
install_cmd="brew install podman"
plan_cmd="brew info podman"
manual_note="macOS: after install run 'podman machine init && podman machine start' once."
fi
;;
MINGW*|MSYS*|CYGWIN*)
if command -v winget >/dev/null 2>&1; then
install_cmd="winget install -e --id RedHat.Podman"
plan_cmd="winget show -e --id RedHat.Podman"
fi
;;
esac
if [[ -z "$install_cmd" ]]; then
echo "✖ don't know how to install Podman here — get it from https://podman.io/docs/installation" >&2
exit 1
fi
[[ $need_sudo -eq 1 ]] && install_cmd="sudo $install_cmd"
[[ -n "$manual_note" ]] && echo "$manual_note" >&2
# --plan: show the real plan and change nothing.
if [[ $PLAN_ONLY -eq 1 ]]; then
echo "plan (no changes will be made): $plan_cmd" >&2
eval "$plan_cmd"
exit 0
fi
# Confirmation (skipped with --yes).
if [[ $ASSUME_YES -ne 1 ]]; then
printf 'Podman is not installed. Install it with "%s"? [y/N] ' "$install_cmd" >&2
read -r reply
case "$reply" in
y|Y|yes|YES) ;;
*) echo "✖ aborted — Podman left uninstalled" >&2; exit 1 ;;
esac
fi
echo "installing Podman: $install_cmd" >&2
eval "$install_cmd" || { echo "✖ install failed (sudo password needed? run it in a terminal)" >&2; exit 1; }
# Confirm the binary is now callable, then run the rootless preflight.
if installed; then
echo "Podman is ready ($(pm_version))" >&2
check_rootless_preflight
exit 0
fi
echo "✖ install ran but podman is still not callable — check the install log" >&2
exit 1
+88
View File
@@ -50,5 +50,93 @@ if ! apt-get install -y --no-install-recommends $PKGS; then
done
fi
# ---- Optional GUI desktop over noVNC -----------------------------------------
# Opt-in via HH_SBX_GUI=1 (set by the launcher for `/sbx <docker|podman> gui`).
# Containers are headless, so a GUI means: install a lightweight XFCE desktop +
# a VNC server, and bridge it to a browser-reachable noVNC websocket on port
# $HH_SBX_GUI_PORT (default 6080). The launcher publishes that port on the host
# loopback (127.0.0.1) only, so the desktop is reachable from this machine's
# browser but never the LAN. Heavy (pulls a desktop), hence strictly opt-in.
if [[ "${HH_SBX_GUI:-0}" == "1" ]]; then
GUI_PORT="${HH_SBX_GUI_PORT:-6080}"
GUI_PASS="${HH_SBX_GUI_PASS:-hackhouse}"
# XFCE (minimal) + a terminal, the X session glue, a VNC server, and the
# noVNC web client + websockify bridge. All apt — works on Ubuntu/Debian/Kali.
# tigervnc-tools carries `vncpasswd`, which --no-install-recommends would
# otherwise drop (it ships only as a recommend of the standalone server) —
# without it the passwd write below is a silent no-op and VNC never auths.
apt-get install -y --no-install-recommends \
xfce4 xfce4-terminal dbus-x11 xfonts-base x11-xserver-utils \
tigervnc-standalone-server tigervnc-tools novnc websockify || true
export USER=root HOME=/root
# TigerVNC 1.15 (Kali/Debian trixie) reads its config from ~/.config/tigervnc
# and aborts with a fatal "Could not migrate /root/.vnc" if the legacy ~/.vnc
# exists, so write straight to the new path. /tmp/.X11-unix must exist + be
# sticky for the X socket; a fresh container may not have it.
VNCDIR=/root/.config/tigervnc
mkdir -p "$VNCDIR" /tmp/.X11-unix
chmod 1777 /tmp/.X11-unix 2>/dev/null || true
# Non-interactive VNC password (obfuscated, not strong auth — the real gate is
# the loopback-only publish + the room password). vncpasswd -f reads stdin.
printf '%s\n' "$GUI_PASS" | vncpasswd -f > "$VNCDIR/passwd" 2>/dev/null || true
chmod 600 "$VNCDIR/passwd" 2>/dev/null || true
cat > "$VNCDIR/xstartup" <<'XS'
#!/bin/sh
unset SESSION_MANAGER DBUS_SESSION_BUS_ADDRESS
exec dbus-launch startxfce4
XS
chmod +x "$VNCDIR/xstartup"
# Start the VNC server on display :1 (TCP 5901). -localhost no lets websockify
# (running in the same netns) reach it; nothing outside the container can —
# only $GUI_PORT is published, and only to host loopback.
if command -v vncserver >/dev/null 2>&1; then
vncserver -kill :1 >/dev/null 2>&1 || true
rm -f /tmp/.X1-lock /tmp/.X11-unix/X1 2>/dev/null || true
vncserver :1 -geometry 1280x800 -depth 24 -localhost no >/dev/null 2>&1 || true
fi
# noVNC web client → websocket → local VNC. Daemonize (nohup, detached stdio)
# so it outlives this `exec bash -s` provision session and keeps serving for
# the life of the container (PID 1 is `sleep infinity`).
if command -v websockify >/dev/null 2>&1; then
NOVNC_WEB=/usr/share/novnc
[[ -d "$NOVNC_WEB" ]] || NOVNC_WEB=/usr/share/webapps/novnc
nohup websockify --web="$NOVNC_WEB" "$GUI_PORT" localhost:5901 \
>/var/log/hh-novnc.log 2>&1 &
fi
fi
# ---- Goose harness (the /ai agent's sandbox `!task` path) --------------------
# Goose ships as a release binary (not apt), so install it via its official
# installer into a system path so every container user can run it. Best-effort:
# a failure here just means the agent falls back to its built-in one-shot
# injector, so it never blocks provisioning. Skip entirely with HH_SBX_GOOSE=0.
if [[ "${HH_SBX_GOOSE:-1}" != "0" ]] && ! command -v goose >/dev/null 2>&1; then
if command -v curl >/dev/null 2>&1; then
GOOSE_BIN_DIR=/usr/local/bin CONFIGURE=false \
bash -c 'curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh | bash' \
|| true
fi
fi
# Container-side Goose config: point it at the host's Ollama via the engine's
# host gateway (passed in as $HH_OLLAMA_HOST by the launcher). The shared shell
# runs as root here, so write it under /root — only if absent, so a tuned config
# survives a re-provision.
if command -v goose >/dev/null 2>&1; then
GOOSE_CFG=/root/.config/goose/config.yaml
if [[ ! -f "$GOOSE_CFG" ]]; then
mkdir -p "$(dirname "$GOOSE_CFG")"
cat > "$GOOSE_CFG" <<EOF
# Written by hh sandbox-bootstrap.sh — Goose runs INSIDE this sandbox and reaches
# the host Ollama over the engine's host gateway. No host filesystem is mounted.
GOOSE_PROVIDER: ollama
GOOSE_MODEL: ${HH_GOOSE_MODEL:-qwen2.5:3b}
OLLAMA_HOST: ${HH_OLLAMA_HOST:-http://host.containers.internal:11434}
EOF
fi
fi
mkdir -p "$(dirname "$SENTINEL")"
date -u +%FT%TZ > "$SENTINEL" # mark done; skip on the next provision pass