Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'cxbox'
- 'ompbox'
- 'lib/**'
- 'integrations/clipboard-ssh/**'
- 'tests/**'
- 'init-firewall.sh'
- 'k8s/**'
Expand All @@ -27,7 +28,7 @@ jobs:
uses: actions/checkout@v7

- name: shellcheck
run: shellcheck ccbox ocbox qcbox cxbox ompbox lib/box-common.sh init-firewall.sh tests/render-test.sh k8s/entrypoint.sh k8s/gen-egress-firewall.sh
run: shellcheck ccbox ocbox qcbox cxbox ompbox lib/box-common.sh init-firewall.sh tests/render-test.sh tests/clipboard-bridge-test.sh integrations/clipboard-ssh/codebox-clipboard-serve k8s/entrypoint.sh k8s/gen-egress-firewall.sh

- name: Render the kustomizations
run: |
Expand All @@ -40,3 +41,6 @@ jobs:

- name: Golden test of the rendered command line
run: tests/render-test.sh

- name: Clipboard image bridge
run: tests/clipboard-bridge-test.sh
5 changes: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ For local development, you can build the image locally:
- `init-firewall.sh` - Firewall initialization script (iptables/ipset)
- `lib/box-common.sh` - Shared launcher engine (sourced by all five launchers): runtime-neutral session spec (`add_mount` / `add_env`) plus two runtime backends that render it, Podman (`podman run`, workstation) and Apptainer (`apptainer exec` on a SIF, long-lived pod; selected with `--runtime` / `CODEBOX_RUNTIME`)
- `tests/render-test.sh` + `tests/golden/` - Golden test of the rendered command line for every launcher (stub runtime; run it, and re-record when a change to mounts/env is intended)
- `tests/clipboard-bridge-test.sh` - Functional test of the clipboard image bridge (host helper + container shim against a stub `wl-paste`, including the SSH-forwarded source)
- `ccbox` / `ocbox` / `qcbox` / `cxbox` / `ompbox` - Host launch scripts (thin wrappers defining harness identity, mounts, and env passthrough)
- `CLAUDE_VERSION` / `OPENCODE_VERSION` / `QWENCODE_VERSION` / `CODEX_VERSION` / `OMP_VERSION` - Version pin files (overridden by `--claude-version` / `--opencode-version` / `--qwen-version` / `--codex-version` / `--omp-version`)
- `k8s/` - Running in a long-lived pod on Kubernetes/OpenShift: `Containerfile` + `entrypoint.sh` (CentOS Stream 9 pod image `quay.io/guimou/codebox-pod`: Apptainer, tmux, the launchers; no dev tooling, that is in the SIF), `cluster/` (SCC + ClusterRole, cluster-admin, once), `base/` + `overlays/example/` (kustomize: service account, PVC, Deployment; the overlay sets namespace, RWX storage class, optional env Secret), `gen-egress-firewall.sh` (OVN EgressFirewall from the firewall domain lists, the pod-level replacement for `--with-firewall`)
- `integrations/herdr-app-agent-memory/` - Herdr app mod (gpui-kit JavaScript panel, installed as `~/.config/herdr-app/mods/agent-memory`): maps each agent to its codebox container via the terminal's foreground `podman run --name`, shows per-agent working set (cgroup `memory.current` minus `inactive_file`) and the `codebox.slice` budget, toasts near `memory.high`; `agent_mem.py` (stdlib Python) reads the cgroups/`/proc` for it, `logic.js` holds the pure helpers
- `integrations/clipboard-ssh/` - Clipboard image server for the machine the user types on (`codebox-clipboard-serve` + systemd user socket/service units), reached by a remote launcher's clipboard bridge through an SSH-forwarded unix socket
- `docs/` - User-facing documentation: `usage.md`, `architecture.md`, `development.md`, `kubernetes.md` (README holds only the minimum and links here — keep them in sync when changing behavior)

## What's Included
Expand Down Expand Up @@ -278,6 +280,7 @@ The launchers also run inside a long-lived pod (`docs/kubernetes.md`): the pod i
- `~/.gitconfig` → `/home/coder/.gitconfig` (read-only, only with `--with-gitconfig`)
- any host directory → the given absolute container path (read-write, or `ro`; only with `--mount HOST:CONTAINER[:ro]`, repeatable)
- npm global prefix → `/home/coder/.npm-global` (read-only, auto-detected)
- Clipboard: the Wayland/X11 socket (read-only), or with SELinux enforcing the clipboard bridge directory → `/run/codebox-clipboard` plus its shim → `/usr/local/bin/wl-paste` and `/usr/local/bin/wl-copy`
- PulseAudio socket (for audio support)
- `/etc/localtime` (for timezone sync)
- **SELinux**: Uses `:z` volume labels for shared relabeling (supports multi-session)
Expand All @@ -295,6 +298,8 @@ Image pasting (CTRL+V) is enabled by default. The container mounts display socke
- **Wayland**: Mounts `$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY` (read-only)
- **X11**: Mounts `/tmp/.X11-unix` and `~/.Xauthority` (read-only)

With SELinux enforcing, the display socket is not wired at all (`selinux_enforcing` in `lib/box-common.sh`): a confined container cannot connect to it. The clipboard goes through the clipboard bridge instead (`clipboard_bridge_*` in `lib/box-common.sh`): a host helper process started by the launcher runs the host's `wl-paste`/`wl-copy` (or `xclip`) on request, talking to a shim mounted as `/usr/local/bin/wl-paste` and `/usr/local/bin/wl-copy` through a FIFO and files in `$XDG_RUNTIME_DIR/codebox-clipboard/<container name>/shared` (mounted at `/run/codebox-clipboard`). `WAYLAND_DISPLAY=codebox-clipboard-bridge` (not a socket) is set in the container because harnesses only use `wl-copy`/`wl-paste --primary` for selection copy and middle-click paste when it is set; without the shims they would fail instead of working. The bridge carries clipboard images (read), the selection (write to clipboard and primary, read of primary), and refuses reads of the regular clipboard text. The local source requires `wl-clipboard` (or `xclip`) on the host. For sessions used over SSH, the helper first asks a clipboard socket forwarded from the user's machine (`$XDG_RUNTIME_DIR/codebox-clipboard-ssh.sock`, `CODEBOX_CLIPBOARD_SOCKET` overrides; needs `python3` on the host), served there by `integrations/clipboard-ssh/` (socket-activated `codebox-clipboard-serve`); the source is chosen per paste. The bridge is also set up when that socket answers at launch or the host has no display. Setup is documented in docs/usage.md "Pasting Images over SSH".

To disable clipboard access: `./ccbox --no-clipboard`

**Note**: Clipboard image pasting in containers has known limitations. If CTRL+V doesn't work, use file paths instead (e.g., paste `/path/to/image.png`).
Expand Down
92 changes: 92 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,102 @@ Image pasting (CTRL+V) requires display server access:
- **macOS**: requires [XQuartz](https://www.xquartz.org/) with "Allow connections from network clients" enabled
- **None found**: the launcher prints a `[WARN] No display server found` line and reports `Clipboard: unavailable` in the status, so a clipboard-blind session is never silent

- **SELinux enforcing (Fedora, RHEL)**: the display socket is **not** wired. SELinux denies a confined container any connection to the compositor or X server, so the socket would be mounted but dead. The clipboard goes through a **host bridge** instead: the launcher starts a small helper on the host that runs the host's `wl-paste`/`wl-copy` (`xclip` on X11) on request, and mounts shims for `wl-paste` and `wl-copy` in the container that ask it through a per-session directory (`$XDG_RUNTIME_DIR/codebox-clipboard/<session>`, removed when the session ends). `WAYLAND_DISPLAY` is set in the container to a name that is not a socket, only so that harnesses use those two commands. The container gets no display access. What the bridge carries:
- **Images** of the clipboard (CTRL+V), read-only.
- **The selection**: text selected in the harness is written to the host clipboard and primary selection, and the primary selection can be read back, so select + middle-click paste works in both directions (including text selected in another window). The terminal also still receives every copy (OSC 52).
- **Not** the text of the regular clipboard (what CTRL+C or a password manager put there): that request is refused. Paste it with the terminal's own paste (CTRL+SHIFT+V).
- It needs `wl-clipboard` (or `xclip` on X11) installed **on the host** (`sudo dnf install wl-clipboard`). Without it the launcher warns that this machine's clipboard cannot be read: middle-click then only pastes what was last selected in that session, and images can only come from an SSH-forwarded clipboard (below).
- The bridge uses the clipboard of the machine running the launcher. When you work on that machine over SSH, see [Pasting Images over SSH](#pasting-images-over-ssh) to make it read the images of the machine you are typing on instead.

To disable clipboard access: `ccbox --no-clipboard`

**Note:** clipboard image pasting in containers has known limitations. If CTRL+V doesn't work, use file paths instead (e.g., paste `/path/to/image.png`).

## Pasting Images over SSH

When the launcher runs on a remote machine (plain `ssh`, or a terminal such as Herdr or Ghostty connected through it), the image you copied is on the clipboard of the machine in front of you, which the remote machine cannot see. Text is not affected: copies reach your local clipboard through the terminal (OSC 52), and you paste with the terminal's own paste. Middle-click pastes the remote machine's primary selection, or what was last selected in that session; the local primary selection is not forwarded.

For images, the clipboard bridge described above can ask your local machine, through a unix socket forwarded by SSH:

```
local machine (laptop) remote machine
---------------------- --------------
clipboard harness in the container: CTRL+V
^ wl-paste / xclip | wl-paste shim
codebox-clipboard-serve v
^ $XDG_RUNTIME_DIR/codebox-clipboard.sock bridge helper (started by the launcher)
| |
+------------ ssh RemoteForward <--------------+ $XDG_RUNTIME_DIR/codebox-clipboard-ssh.sock
```

Only image types are served (`png`, `jpeg`, `gif`, `webp`, `bmp`): the local server refuses anything else, so clipboard text never leaves your machine this way.

### 1. Local machine: install the clipboard server

Requires Linux with systemd and `wl-clipboard` (`xclip` on X11). From a checkout of this repository:

```bash
sudo dnf install wl-clipboard
install -D -m 755 integrations/clipboard-ssh/codebox-clipboard-serve ~/.local/bin/codebox-clipboard-serve
install -D -m 644 -t ~/.config/systemd/user \
integrations/clipboard-ssh/codebox-clipboard.socket \
integrations/clipboard-ssh/codebox-clipboard@.service
systemctl --user daemon-reload
systemctl --user enable --now codebox-clipboard.socket
```

Nothing runs permanently: systemd listens on `$XDG_RUNTIME_DIR/codebox-clipboard.sock` (mode `0600`) and starts the script for the duration of one request. Check it with an image on the clipboard:

```bash
printf 'list\n' | python3 -c 'import socket,sys,os; s=socket.socket(socket.AF_UNIX); s.connect(os.environ["XDG_RUNTIME_DIR"]+"/codebox-clipboard.sock"); s.sendall(sys.stdin.buffer.read()); s.shutdown(1); print(s.makefile().read())'
# ok
# image/png
```

### 2. Local machine: forward the socket in `~/.ssh/config`

```
Host my-remote
RemoteForward /run/user/REMOTE_UID/codebox-clipboard-ssh.sock /run/user/LOCAL_UID/codebox-clipboard.sock
```

`LOCAL_UID` is `id -u` on the local machine, `REMOTE_UID` is `id -u` on the remote one (the first path is where the socket appears on the remote machine: `$XDG_RUNTIME_DIR/codebox-clipboard-ssh.sock` there). Anything that connects with the system `ssh` and this host entry gets the forward, including terminals that open their remote sessions through it.

### 3. Remote machine: let `sshd` replace a stale socket

When a connection drops, the forwarded socket file stays behind and the next connection cannot create it again (`Warning: remote port forwarding failed for listen path ...`). Allow `sshd` to replace it, once, as root:

```bash
echo 'StreamLocalBindUnlink yes' | sudo tee /etc/ssh/sshd_config.d/50-codebox-clipboard.conf
sudo systemctl reload sshd
```

The remote machine also needs `python3` on the host (the bridge helper uses it to talk to the socket). Nothing has to be installed in the container image.

### 4. Use it

Reconnect, then start the launcher on the remote machine as usual. The status lines tell which sources the bridge has:

```
[INFO] Clipboard: host bridge: images (SSH-forwarded clipboard), selection and middle-click paste
```

Copy an image locally and press CTRL+V in the harness.

How the source is chosen:

- It is decided **for each paste**, not at launch: if something answers on the forwarded socket, the image comes from there; otherwise from the remote machine's own clipboard, when it has a display (and `wl-clipboard`/`xclip`). A session started at the remote machine's own desk and later attached over SSH, or the reverse, pastes from wherever you are connected from.
- A session started while no socket was forwarded still picks it up later, provided the bridge is active for that session: it is whenever SELinux is enforcing on the remote machine or the remote machine has no display. On a remote machine with a display and SELinux not enforcing, the display socket is wired directly instead (see above) unless the forwarded socket answers at launch, so connect first, then launch.
- With several SSH connections to the same remote machine, the last one to connect owns the socket.
- `CODEBOX_CLIPBOARD_SOCKET=/some/path` on the remote machine overrides the socket location.

Security: while you are connected, any process running as your user on the remote machine can fetch the **image** currently on your local clipboard (not text). Remove the `RemoteForward` line, or `systemctl --user disable --now codebox-clipboard.socket`, to turn it off. `--no-clipboard` disables the bridge for a session.

Troubleshooting:

- Status shows `images (host wl-paste)` only, or `images once a clipboard socket is forwarded over SSH`: nothing answers on the remote socket. Check `ls -l $XDG_RUNTIME_DIR/codebox-clipboard-ssh.sock` on the remote machine and run `ssh -v` to see whether the forward was refused (step 3).
- The socket answers but pasting does nothing: on the local machine, `journalctl --user -u 'codebox-clipboard@*'` shows the server's errors (typically a missing `wl-clipboard`).

## Agent Teams (ccbox only, experimental)

Agent teams let you coordinate multiple Claude Code instances working in parallel:
Expand Down
64 changes: 64 additions & 0 deletions integrations/clipboard-ssh/codebox-clipboard-serve
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
# Clipboard image server for codebox sessions running on another machine.
#
# Runs on the machine you are typing on, once per connection (systemd socket
# activation, see codebox-clipboard.socket): stdin/stdout are the connection.
# The launcher on the remote machine reaches it through a unix socket
# forwarded over SSH and asks for the clipboard image when you press CTRL+V
# in a harness (docs/usage.md, "Pasting Images over SSH").
#
# Protocol: one request line, "list" or "get <mime type>"; the answer is
# "ok\n" followed by the payload (the image types, one per line, or the raw
# image), or "no\n". Only image types are ever served: clipboard text is
# never sent, whatever is asked.

TYPES='image/(png|jpeg|jpg|gif|webp|bmp)'

op="" type=""
read -r -t 5 op type || true
type="${type%$'\r'}"

runtime_dir="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
tool=""
if [[ -n "${WAYLAND_DISPLAY:-}" || -S "${runtime_dir}/wayland-0" ]]; then
tool="wl-paste"
export XDG_RUNTIME_DIR="$runtime_dir" WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-wayland-0}"
elif [[ -n "${DISPLAY:-}" ]]; then
tool="xclip"
fi
if [[ -z "$tool" ]] || ! command -v "$tool" > /dev/null 2>&1; then
echo "codebox-clipboard-serve: no clipboard tool (install wl-clipboard, or xclip on X11)" >&2
printf 'no\n'
exit 0
fi

paste() { # list | get TYPE
if [[ "$tool" == wl-paste ]]; then
if [[ "$1" == list ]]; then timeout 3 wl-paste --list-types; else timeout 5 wl-paste --type "$2"; fi
else
if [[ "$1" == list ]]; then timeout 3 xclip -selection clipboard -t TARGETS -o; else timeout 5 xclip -selection clipboard -t "$2" -o; fi
fi 2> /dev/null
}

case "$op" in
list)
if types=$(paste list | grep -E "^${TYPES}\$"); then
printf 'ok\n%s\n' "$types"
else
printf 'no\n'
fi
;;
get)
tmp=$(mktemp) || { printf 'no\n'; exit 0; }
trap 'rm -f "$tmp"' EXIT
if [[ "$type" =~ ^${TYPES}$ ]] && paste get "$type" > "$tmp" && [[ -s "$tmp" ]]; then
printf 'ok\n'
cat "$tmp"
else
printf 'no\n'
fi
;;
*)
printf 'no\n'
;;
esac
10 changes: 10 additions & 0 deletions integrations/clipboard-ssh/codebox-clipboard.socket
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=codebox clipboard image server (image pasting in SSH sessions)

[Socket]
ListenStream=%t/codebox-clipboard.sock
SocketMode=0600
Accept=yes

[Install]
WantedBy=sockets.target
8 changes: 8 additions & 0 deletions integrations/clipboard-ssh/codebox-clipboard@.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=codebox clipboard image request

[Service]
ExecStart=%h/.local/bin/codebox-clipboard-serve
StandardInput=socket
StandardOutput=socket
StandardError=journal
Loading