Sandboxed opencode web interface for editing a lichen.page site — tailnet-only container, Caddy basic auth, GLM 5.2
README.md

emily-sandbox #

A sandboxed opencode at emily.commoninternet.net where a non-technical user talks to an AI agent that edits and publishes her lichen.page website.

The design and its reasoning live in PLAN.md. This file is how to run it.

Shape #

Emily's browser
   │  https://emily.commoninternet.net
   ▼
gateway node                       TLS passthrough on :443 (and :80) to a tailnet IP
   │  tailnet (WireGuard)
   ▼
emily-sandbox container            its own tailnet node
   ├── caddy       :443            real Let's Encrypt cert, basic_auth — the only way in
   ├── opencode    127.0.0.1:4096  the agent + web UI, loopback only
   ├── tailscaled                  joins the tailnet
   └── lm                          clones / pushes her site

The host running this container exposes nothing new publicly. There is no ports: block in docker-compose.yml and no nginx vhost in the nix module; both omissions are deliberate.

Authentication #

One password prompt, from Caddy, username emily. Caddy then replaces her credentials with opencode's own (OPENCODE_SERVER_PASSWORD) on the way upstream, so:

  • she is never asked twice,
  • her password is not what opencode checks,
  • opencode is unreachable except through the authenticated proxy — it binds loopback only.

opencode itself runs with permission: allow (no approval prompts), which is only acceptable because the container is the boundary and holds nothing but her own site.

Secrets #

Five files, referenced by path, never committed and never inlined into nix. They follow this host's /secrets convention (plaintext, mode 600, owned by loops, alongside store.yaml):

/secrets/emily-sandbox/
├── tailscale-authkey          tagged, non-ephemeral — joins the tailnet
├── opencode-zen-key           dedicated secondary OpenCode Zen key (GLM 5.2 inference)
├── lichen-token               Emily's dash.lichen.page API token, scope only_safe
├── emily-password             her login passphrase (plaintext; bcrypt-hashed at container start)
└── opencode-server-password   internal, injected by Caddy — she never sees it

Its own subdirectory, deliberately — not /secrets/files. That directory holds the operator's gitea, tangled and cc-ci SSH keys; bind-mounting it would hand the sandbox the entire credential set, which is exactly what PLAN.md §1 forbids. Only /secrets/emily-sandbox is ever mounted.

All are mode 600 and owned by uid 1000 on the host. They are bind-mounted read-only at /run/secrets. The container's emily user is uid 10001 specifically so she cannot read them — only root can, before the entrypoint drops privileges. The one exception is the Zen key, which by necessity ends up in her auth.json because opencode needs it; that is why it must be a dedicated, independently revocable key.

systemd refuses to start the stack if any secret is missing or has the wrong mode (ExecStartPre preflight in the nix module).

Running it #

Requires access to the docker socket (membership in the docker group, or root).

export EMILY_SECRETS_DIR=/secrets/emily-sandbox
docker compose up -d --build          # cold build compiles lm from Rust source; slow
docker logs emily-sandbox | grep -A2 'TAILNET ADDRESS'

That last line prints the address to point the gateway at. It is stable across restarts because the tailscale node identity lives on a named volume — do not delete tailscale-state.

Going live via nix, once approved:

imports = [ /srv/project-orchestrator/projects/emily-lichen/nix/emily-sandbox.nix ];

Before any push: ./tools/check-secrets.sh — asserts nothing credential-shaped is tracked, in the working tree or in history.

Verified vs. assumed #

Checked directly against the real tooling rather than taken on trust:

Claim Status
opencode serve serves the web UI at /, not just a JSON API verified (HTTP 200, text/html)
OPENCODE_SERVER_PASSWORD is HTTP Basic, username must be opencode verified by probe
auth.json shape is {"<provider>":{"type":"api","key":…}} verified against a working install
opencode/glm-5.2 is a real model id verified via opencode models (61 models on Zen)
lm auth login --server … --token … is the correct invocation verified in lichen-cli source
Emily's token scope is only_safe verified live (GET /api/token-permission-scope)
Her site exists (bookgroup.lichen.page) verified live (GET /api/sites)
A safe-scoped token cannot escalate itself to full verified — unsafe_action_guard returns 403

Confirmed on the first real boot:

Claim Status
tailnet join yields a stable address (100.93.34.127) verified — survives rebuilds via the state volume
lm auth login + lm clone bookgroup.lichen.page succeed verified in the entrypoint log
opencode returns 401 unauthenticated on loopback verified — its auth is genuinely engaged
Caddy listens on :443 and :80; :80 308-redirects to https verified
the internal password is absent from argv verified — 0 occurrences in /proc/*/cmdline

Confirmed once the gateway forwarding went live:

Claim Status
TLS-ALPN-01 succeeds through the passthrough verified — cert issued ~15s after restart
the browser gets a publicly-trusted cert, no warning verified — Let's Encrypt, expires Nov 12 2026
401 unauthenticated / 401 wrong password / 200 with hers verified over the public hostname
Caddy's upstream credential swap reaches opencode verified — the API answers through the proxy
bare hostname reaches the site verified — http:// 308-redirects to https://

And with the provider corrected to Zen proper:

Claim Status
the model actually answers through the public hostname verified — HTTP 200 in 4s via opencode/glm-5.2
lichen-editor is registered and is the only user-facing primary verified — opencode agent list
the lichen-cli skill is discovered verified — appears in resolved permission patterns

Still unconfirmed:

  • that --cors https://emily.commoninternet.net suffices for the UI's streaming connection — the API path is proven, but not a real browser session;
  • the lichen-cli skill's invocation — that needs a real publish to her live site;
  • what Emily's first unaided session actually feels like.

Zen vs Zen Go — they are not the same product #

PLAN.md originally described the provider opencode-go as "OpenCode Zen". They are two different products with separate billing, and the same key authenticates against both:

Provider id Base URL Billing Models Result
opencode-go opencode.ai/zen/go/v1 Go plan, monthly cap 25 429 once the cap is hit
opencode opencode.ai/zen/v1 account balance 61 200

This container uses opencode/glm-5.2 — Zen proper. The Go plan's monthly cap produced 429 GoUsageLimitError, and because that error is flagged isRetryable, opencode retried silently rather than surfacing it: a prompt hung for 520 seconds with no output. That is the worst possible failure mode for a non-technical user, who has no reason to suspect a billing limit. If you move back to the Go plan, add a visible message for this case.

The agent she talks to #

A single primary agent, lichen-editor (assets/agents/lichen-editor.md), with the built-in build and plan agents disabled — so she lands on it with no agent to choose and no Tab-switching to discover. Its prompt covers her site, her non-technical vantage point (no jargon, no file paths, no commands), the edit-versus-publish distinction, and that nothing is unrecoverable.

It is paired with the lichen-cli skill (assets/skills/lichen-cli/SKILL.md), loaded on demand via opencode's native skill tool, documenting lm pull / lm push, undoing changes with git revert, what a safe-scoped token refuses, and how to diagnose a failed publish.

Both are staged in the image under /opt/emily-assets/ and copied into her home at start, so rebuilds ship updated instructions without wiping the persistent volume.

Verified: opencode agent list shows lichen-editor (primary) and no build/plan; the skill is discovered (it appears in opencode's resolved permission patterns); and a live prompt through the public hostname answered correctly in 4s via opencode/glm-5.2. The skill's invocation is not yet exercised — that needs a real publish to her live site.

Bugs found by actually running it #

Recorded because each one passed static validation and only failed at runtime:

  1. python3-minimal ships without json. The entrypoint died writing auth.json, crash-looping the container. Fixed by installing full python3.
  2. install -d -o emily a/b/c chowns only the final component. .local and .config were left root-owned, so opencode got EACCES creating .local/state. Fixed with mkdir -p plus a recursive chown, which also self-heals a volume an earlier boot got wrong.
  3. An unsubstituted @@ACME_EMAIL@@ reached Let's Encrypt as the contact address. caddy validate accepts a placeholder as a perfectly valid string, so this only surfaced minutes later as invalidContact. The renderer now fails loudly on any leftover placeholder.
  4. runuser -- env VAR=… puts the value in world-readable argv. Replaced with setpriv inheriting an exported environment, scoped to a subshell so it does not also move Caddy's certificate storage off its volume.
  5. The original healthcheck probed https://127.0.0.1/, which sends no SNI and depends on a certificate that cannot exist before the gateway is wired up. It now asserts Caddy's admin API and opencode's 401 independently.

What only_safe does and does not buy #

It guarantees her data cannot be destroyed: no site deletion, no force-push, no force-pull, no git compact. Writes are append-only in effect and content is git-backed, so any bad edit is revertible.

It is not a boundary against a hostile token holder. Per the lichen source, configuration changes (git remote, sync, publish settings) and publishing itself are all safe-scope operations. The recovery story is git history, not the token scope.