Files
opencode-sandbox/lib/init.sh
T
k.denisov 64c222a084 opencode-sandbox: OpenCode 2 in a sandbox for any project
Runs OpenCode 2 with full permissions while containing its mistakes:

- egress filter: squid in a container per project; squid.conf is rendered
  from layered egress.conf files (package, user, project, local) with
  allow/block/connect rules and expect-pass/expect-block self-tests
- netlock: nftables rejects direct egress for the opencode-sandbox group
  (installed once with sudo as a systemd unit)
- bubblewrap: read-only host, writable project, worktrees and state;
  credentials hidden; ssh keys via the host's ssh-agent; session bus
  replaced by an xdg-dbus-proxy limited to notifications; no permission
  prompts (sudo and systemd-run denied); refuses to run unsandboxed
- per-project state in ~/.local/share/opencode-sandbox/<name>
- worktrees: `wt add|rm|list` with project hooks
- skills mounted per project; the opencode-sandbox skill explains the
  environment to the agent
- plugins as submodules: context-panel, skill-compact-resurrect;
  global config adds opencode-notifier and cc-safety-net
- README in English and Russian
2026-10-30 01:00:02 -07:00

32 lines
1.3 KiB
Bash

# shellcheck shell=bash
# opencode-sandbox init: add .opencode-sandbox/ to the current git repository
ocsb_init() {
local root t=${OCSB_HOME}/templates/project f
root=$(git rev-parse --show-toplevel 2>/dev/null) || ocsb_die "run init inside a git repository"
if [[ -f ${root}/.opencode-sandbox/sandbox.conf ]]; then
ocsb_die "${root}/.opencode-sandbox already exists"
fi
mkdir -p "${root}/.opencode-sandbox/hooks" "${root}/.opencode-sandbox/local"
cp "${t}/sandbox.conf" "${t}/egress.conf" "${root}/.opencode-sandbox/"
printf '/local/\n' >"${root}/.opencode-sandbox/.gitignore"
for f in "${t}"/hooks/*.example; do
cp "${f}" "${root}/.opencode-sandbox/hooks/"
done
if [[ ! -e ${root}/.cc-safety-net/policy.json ]]; then
mkdir -p "${root}/.cc-safety-net"
cp "${t}/cc-safety-net-policy.json" "${root}/.cc-safety-net/policy.json"
fi
cat <<EOF
✓ created ${root}/.opencode-sandbox/
sandbox.conf settings (ports, writable paths, skills, worktrees) — commit it
egress.conf domains for this project — commit it
hooks/ worktree hooks: drop .example and chmod +x to enable
local/ personal overrides (sandbox.conf, egress.conf), git-ignored
Next:
opencode-sandbox doctor check the host
opencode-sandbox run start OpenCode in the sandbox
EOF
}