Agent Sandboxes, part four: letting someone else watch (or drive) your Claude

claude-code sandboxing security homelab agents ssh

Part three was all about Xcode. Since then Agent Sandboxes has picked up thirteen more commits, and the big one is for the moment you want somebody else to see what your agent is up to:

Can I have a go?

Until this week the only answer was “come round to my house”. Everything lives on a box in the loft, behind NAT, and the web UI is the last thing I’d put on the internet. It has a host shell in it.

What’s in this one:

So what’s the problem?

Sharing a terminal with someone is easy if you don’t care what else they can reach. I do care, so the list of things I didn’t want was longer than the list of things I did:

  1. No port forward on the home router, and nothing that needs a static IP.
  2. The guest never touches the real UI. No API, no settings, no other workspaces, definitely no host shell.
  3. One link, for one person, that expires and can be killed mid-session.
  4. No third-party tunnel service sat in the middle of my terminal.

The Share tab

Each workspace now has a Share tab that makes a link for one guest. You choose what they get:

  • The Claude terminal, either watch only or watch and type. Watch only is a read-only tmux client that ignores the guest’s window size (so they can’t resize your session by having a small laptop), and the page drops their keystrokes as well.
  • The project files, optionally, to download or to upload too. Only inside the workspace folder, with symlinks resolved so nothing points its way out.
  • The sandbox’s browser desktop, optionally, and only for a guest who can type.

Links last from an hour to seven days. Revoke or New link disconnects the guest on the spot, the sidebar shows when somebody’s in your terminal, and joins and file transfers go into an audit log.

A guest who types is Claude in that workspace, with its keys, its tokens, its network access and its files. That’s the whole point of letting them drive, but it’s worth saying out loud before you send the link to anyone.

Your own VPS as the relay

Guests never reach the host in the loft. They reach a cheap VPS, and the host reaches the VPS:

guest ─https─▶ Caddy on your VPS ─▶ 127.0.0.1:18443 ═ ssh -R from home ═▶ 127.0.0.1:9443

The host dials out with a reverse SSH tunnel, so there’s no port forward and CGNAT doesn’t matter. On the home end the tunnel lands on a separate share listener, which only has guest routes. The UI’s API and the host shell aren’t behind an auth check there, they simply aren’t routed, and my own sign-in cookie means nothing to it.

The VPS end is locked down to match. The tunnel’s key belongs to a user that can open that one reverse forward and nothing else:

restrict,port-forwarding,permitlisten="127.0.0.1:18443"

No shell, no other forwards. If the VPS gets popped, the attacker gets a Caddy config and one end of a tunnel to a listener that only speaks “guest”.

Setup is a card in Settings. You give it two DNS names and the VPS address, it shows you the VPS’s SSH host key fingerprint to confirm (then pins it), and it hands you a script to run on the VPS. The UI runs the tunnel itself and there’s a Check from the internet button that tests DNS, the certificate, Caddy and the tunnel in one go, the way a guest would arrive.

What went wrong on the way

Five of the thirteen commits are that relay meeting the real world, on the same day.

The VPS already had opinions about SSH. The first script put the tunnel key in the new user’s authorized_keys, which is fine on a fresh server. On one with its own AuthorizedKeysFile, an AllowUsers list or a fussy StrictModes, the tunnel gets a flat Permission denied (publickey). The script now puts the key in a root-owned file that sshd uses for that one user, adds the user to AllowUsers if there is one, takes a copy of the sshd config first and puts it all back if sshd -t doesn’t like the result.

Cloudflare. Behind the orange cloud, Flexible SSL gives you a redirect loop, and the free certificate only covers one level of subdomain, so desktop.share.example.com fails TLS while share-desktop.example.com is fine. The check now tells you which of those you’ve hit, and there’s a Behind Cloudflare’s proxy setting that makes Caddy accept only Cloudflare’s edge.

update-host did nothing. I’d pulled by hand, so its own pull found nothing new and it exited, leaving the UI running old code and showing me the old VPS script. It now compares the UI’s start time with its files and applies everything if the UI is behind.

More on passing credentials in the sandboxes

That’s sharing done. This next bit is unrelated to it, and picks up a thread from part one instead: tokens that aren’t bearer tokens.

The proxy trick from part one (the agent holds a placeholder, the real token gets swapped in on the way out) assumed Authorization: Bearer. Plenty of APIs didn’t get that memo.

Four places a secret can go. The agent’s notes tell it where to put the placeholder.

A custom token can now be sent as a header of any name, a query parameter, part of the URL path, or HTTP Basic auth. What the proxy can’t do is swap a value inside a request body, a file or a URL typed into a browser. For those there are now plain values: things that aren’t secret but should still be tracked and handed only to chosen workspaces (client IDs, project IDs), set as a real environment variable.

In other updates

App Store screenshots. The Apple build workers can now take a planned set of screenshots: several Simulator devices, light and dark, multiple locales, a clean 9:41 status bar, up to 60 a job. Either the app is steered by launch arguments, or your UI tests do the tapping and attach the shots. That work also closed a hole of its own; the worker’s output folder is shared read-write into the VM, so a symlink planted there could have handed over a file from the Mac. It’s read with O_NOFOLLOW now.

The sidebar stopped crying wolf. Opening a workspace resized its tmux window, Claude repainted, and the sidebar decided that was “activity”. It now hashes the visible text and only counts real changes.

The push that wouldn’t. Publishing part three failed with No user exists for uid 1000. The sandbox couldn’t read the user database, and ssh won’t even start without it, so git push died before it got anywhere near a key. The nono profile now lists /etc/passwd and /etc/group explicitly. Not my finest hour of debugging, I blamed the agent first.

TL;DR

  • Share one workspace with one person: watch or type, optional files and desktop, expiring and revocable.
  • Guests come in through your own VPS over a reverse SSH tunnel. Nothing opens at home, and the guest listener has no route to the real UI.
  • Separately, credentials: custom tokens go wherever the API wants them, and non-secret values can be real env vars.
  • Screenshot plans for App Store listings, and a handful of fixes I earned the hard way.

The code’s at metahertz/agent-sandboxes. If you set the relay up on a VPS with an even stranger sshd config than mine, I’d love to know what it does.

Happy hacking!

-Matt

← All posts