# shellcheck shell=bash DESCRIPTION="Installs Node.js and srt, and the sandbox keeps a (fake) agent in: files, network, local servers" TIER=quick source "$CONNECTOR/configure.d/30-agents.sh" source "$CONNECTOR/configure.d/50-ai-servers.sh" PROJECT="$HOME/proj" # Run a command as the "opencode" agent, in the sandbox, from a project sandboxed() { (cd "$PROJECT" && "$CONNECTOR/sandbox/bin/opencode" "$@") } fetch() { sandboxed /usr/bin/curl -fsS -o /dev/null --max-time 20 "$1" } zsh_finds_sandboxed() { [ "$(zsh -ic 'command -v opencode' 2> /dev/null)" = "$CONNECTOR/sandbox/bin/opencode" ] } scenario() { local node server step "Installing Node.js and srt" check "tool_ensure node srt" tool_ensure node srt check "Node.js is 22.12 or later" node_ok check "srt is found" srt_path # The agent is a stand-in that runs what it's given, so commands can be # tried in its sandbox mkdir -p "$HOME/.local/bin" "$PROJECT" "$HOME/.ssh" printf '#!/bin/bash\nexec "$@"\n' > "$HOME/.local/bin/opencode" chmod +x "$HOME/.local/bin/opencode" echo secret > "$HOME/.ssh/smoke-secret" step "Files" check "the agent runs in the sandbox" sandboxed /usr/bin/true check_not "it can't read ~/.ssh" sandboxed /bin/cat "$HOME/.ssh/smoke-secret" check_not "it can't read the keychains" sandboxed /bin/ls "$HOME/Library/Keychains" check "it can write in its project" sandboxed /usr/bin/touch "$PROJECT/written" check_not "it can't write elsewhere in your home folder" sandboxed /usr/bin/touch "$HOME/outside" check "it can write in /tmp" sandboxed /usr/bin/touch /tmp/smoke-written check "it can make temp files (mktemp)" sandboxed /usr/bin/mktemp check "it can open a pty (allowPty)" sandboxed /usr/bin/script -q /dev/null /usr/bin/true check_not "it won't start in your home folder" bash -c "cd ~ && '$CONNECTOR/sandbox/bin/opencode' /usr/bin/true" check "unsandboxed runs it outside" bash -c "cd '$PROJECT' && '$CONNECTOR/sandbox/bin/unsandboxed' opencode /bin/cat '$HOME/.ssh/smoke-secret'" step "Network" check "it reaches an allowed site (registry.npmjs.org)" fetch https://registry.npmjs.org/ check_not "it doesn't reach others (example.com)" fetch https://example.com/ step "An LLM server on this Mac" node="$(tool_path node)" "$node" -e 'require("http").createServer((q, s) => { s.setHeader("content-type", "application/json"); s.end(JSON.stringify({data: [{id: "smoke-model"}]})); }).listen(11434, "127.0.0.1")' & server=$! sleep 2 check_eq "server_models reads its models" smoke-model "$(server_models localhost:11434)" check_not "the agent can't reach it before it's allowed" fetch http://localhost:11434/v1/models check "sandbox_allow localhost:11434" sandbox_allow localhost:11434 check "...then it can, through srt's proxy" fetch http://localhost:11434/v1/models check "sandbox_disallow" sandbox_disallow localhost:11434 check_not "...then it can't again" fetch http://localhost:11434/v1/models kill "$server" 2> /dev/null step "Shell and Claude Code" check "put_on_path" put_on_path check "a new zsh finds sandbox/bin's opencode first" zsh_finds_sandboxed check "turn_on_claude_sandbox" turn_on_claude_sandbox check "Claude Code's sandbox is on" claude_sandbox_on }