8000 feat(sandbox): share the office desktop with people through /pi-desktop by geminixiang · Pull Request #178 · geminixiang/mikan · GitHub 8000
[go: up one dir, main page]

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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ change in a minor release.

## [Unreleased]

### Added

- `/pi-desktop` (`/desktop` on other platforms) sends a private 24-hour link to the conversation's
desktop in the managed `oci` sandbox: watch or use the browser the agent drives, open its tabs,
DevTools, or a terminal. "Take control" pauses the agent's browser until you hand it back, and the
agent can hand you a step such as signing in with `jev_browser`'s `handOff`, which posts the step
with a link and ends its turn. The desktop starts on the first link, stops with the sandbox's idle
stop, and keeps the sandbox from stopping while someone has it open. It needs the sandbox image of
this release; an office whose sandbox still runs an older image gets it after the sandbox idles out.
Register `/pi-desktop` in the Slack app manifest.

### Changed

- `jev_browser` closes only tabs it opened when it passes its three-tab limit, so tabs a person
opened stay open.
- The sandbox image adds `sway`, `wayvnc`, and `foot` (about 1 MB) and the `mikan-desktop` script.

## [1.4.0] - 2026-10-11

### Added
Expand Down
104 changes: 104 additions & 0 deletions deploy/docker/mikan-desktop
basename "$socket"
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
# The office desktop that mikan shares with people (ADR 0025): a headless Sway
# session with wayvnc on 127.0.0.1:6080. mikan runs this from the host with
# `<engine> exec`; jev_browser reads `status` to draw on the display and to
# respect who controls the browser.
set -euo pipefail

export XDG_RUNTIME_DIR=/run/user/0
export LANG=C.UTF-8
VNC_PORT=6080
CONTROL_FILE=/dev/shm/mikan-browser-control
LOG_FILE=/tmp/mikan-desktop.log

display_socket() {
local socket
for socket in "$XDG_RUNTIME_DIR"/wayland-*; do
case "$socket" in *.lock) continue ;; esac
if [ -S "$socket" ]; then
return
fi
done
}

sway_running() {
[ -n "$(display_socket)" ] && pgrep -x sway >/dev/null
}

vnc_listening() {
local port
port=$(printf '%04X' "$VNC_PORT")
awk -v port=":$port" '$2 ~ port"$" && $4 == "0A" { found = 1 } END { exit !found }' /proc/net/tcp
}

running() {
sway_running && pgrep -x wayvnc >/dev/null && vnc_listening
}

wait_running() {
for _ in $(seq 100); do
running && return 0
sleep 0.1
done
tail -20 "$LOG_FILE" >&2
return 1
}

case "${1:-}" in
start)
mkdir -p "$XDG_RUNTIME_DIR"
chmod 700 "$XDG_RUNTIME_DIR"
exec 9>"$XDG_RUNTIME_DIR/.mikan-desktop.lock"
flock 9
running && exit 0
if sway_running; then
pkill -x wayvnc || true
SWAYSOCK="$XDG_RUNTIME_DIR/sway-ipc.$(id -u).$(pgrep -xo sway).sock" swaymsg exec "$0 vnc" >/dev/null 9>&-
wait_running
exit
fi
pkill -x wayvnc || true
pkill -x sway || true
rm -f "$XDG_RUNTIME_DIR"/wayland-* "$XDG_RUNTIME_DIR"/sway-ipc.*
WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_LIBINPUT_NO_DEVICES=1 \
setsid sway -c /etc/mikan/sway.conf </dev/null >"$LOG_FILE" 2>&1 9>&- &
wait_running
;;
vnc)
exec wayvnc --websocket --max-fps=60 127.0.0.1 "$VNC_PORT"
;;
status)
display=""
control=agent
if running; then
display=$(display_socket)
control=$(cat "$CONTROL_FILE" 2>/dev/null || echo agent)
fi
printf '{"display":"%s","control":"%s"}\n' "$display" "$control"
;;
control)
case "${2:-}" in
agent | user) echo "$2" >"$CONTROL_FILE" ;;
*)
echo "usage: mikan-desktop control agent|user" >&2
exit 2
;;
esac
;;
connect)
running || exit 3
exec node -e '
const socket = require("node:net").connect(Number(process.argv[1]), "127.0.0.1");
process.stdin.pipe(socket);
socket.pipe(process.stdout);
socket.on("close", () => process.exit(0));
socket.on("error", () => process.exit(1));
process.stdin.on("end", () => socket.end());
' "$VNC_PORT"
;;
*)
echo "usage: mikan-desktop start|status|control agent|user|connect" >&2
exit 2
;;
esac
6 changes: 6 additions & 0 deletions deploy/docker/mikan-sandbox.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
file \
fonts-liberation \
fonts-noto-cjk \
foot \
git \
imagemagick \
jq \
openssh-client \
python-is-python3 \
python3-pip \
ripgrep \
sway \
tini \
tzdata \
unzip \
wayvnc \
wget \
xz-utils \
zip \
Expand Down Expand Up @@ -112,6 +115,9 @@ RUN printf '%s\n' '[externally-managed]' \
' Or create a project venv: uv venv .venv && uv pip install --python .venv pandas' \
> "$(python3 -c 'import sysconfig; print(sysconfig.get_path("stdlib"))')/EXTERNALLY-MANAGED"

COPY deploy/docker/mikan-desktop /usr/local/bin/mikan-desktop
COPY deploy/docker/mikan-sway.conf /etc/mikan/sway.conf

RUN rmdir /root/.ssh 2>/dev/null; test "$(ls -A /root | tr "\n" " ")" = ".bashrc .profile " || (ls -la /root && exit 1)

WORKDIR /workspace
Expand Down
9 changes: 9 additions & 0 deletions deploy/docker/mikan-sway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output HEADLESS-1 resolution 1280x800 position 0,0
output * bg #1a1b26 solid_color
default_border pixel 2
gaps inner 4
client.focused #7aa2f7 #7aa2f7 #1a1b26 #7aa2f7
bindsym Mod1+Return exec foot
bindsym Mod1+Shift+q kill
exec /usr/local/bin/mikan-desktop vnc
exec foot
5 changes: 5 additions & 0 deletions deploy/examples/slack-agent-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"description": "session viewer",
"should_escape": false
},
{
"command": "/pi-desktop",
"description": "office desktop",
"should_escape": false
},
{
"command": "/pi-sandbox",
"description": "sandbox",
Expand Down
5 changes: 5 additions & 0 deletions deploy/examples/slack-app-manifest.e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
"description": "session",
"should_escape": false
},
{
"command": "/pi-desktop",
"description": "office desktop",
"should_escape": false
},
{
"command": "/pi-sandbox",
"description": "sandbox",
Expand Down
5 changes: 5 additions & 0 deletions deploy/examples/slack-app-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"description": "session viewer",
"should_escape": false
},
{
"command": "/pi-desktop",
"description": "office desktop",
"should_escape": false
},
{
"command": "/pi-sandbox",
"description": "sandbox",
Expand Down
40 changes: 40 additions & 0 deletions docs/adr/0025-office-desktop-shared-with-people.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
status: accepted
---

# People share the office's desktop with the agent

A Conversation office's Sandbox runtime is the agent's computer. mikan lets the members of the conversation see and operate it from a browser: a Wayland desktop in the office container, shown through noVNC behind mikan's web server, where the browser that `jev_browser` drives appears as an ordinary window.

## Context

`jev_browser` runs headless Chromium through agent-browser with a fresh profile per thread, so nobody can watch it, log it into a site, or solve a challenge for it, and no login state survives. The research in [`docs/research/browser-sharing-2026-10.md`](../research/browser-sharing-2026-10.md) compared a page-only CDP screencast with a full remote desktop and measured three prototypes:

| | Wayland (Sway + wayvnc) | X11 (Xvfb + x11vnc) | Page-only CDP screencast |
| ---------------------------- | ------------------------------------------------------------------------- | ------------------- | ------------------------ |
| Shows | the whole desktop: browser UI, tabs, DevTools, a terminal, other programs | the whole desktop | the active page only |
| Image growth | +3 MB | +77 MB | 0 |
| Memory with the browser open | +93 MB over headless | +132 MB | 0 |
| First frame | 290 ms | 2,685 ms | 288 ms |
| Key to screen, median | 58 ms | 77 ms | 55 ms |
| Frame updates | 60 fps | about 40 fps | on change |

Hosted and open-source agent browsers split the same way: page views for handing a step to a person (Browserbase, Steel, Browserless, Hyperbrowser) and full desktops for sharing (Kernel, Anthropic's computer-use demo, E2B Desktop, Neko).

## Decision

- **Desktop.** The sandbox image ships `sway`, `wayvnc`, and `foot`. The desktop is not running by default; it starts in the office container when a member first asks for a link, and it stops when the container stops for idleness. Sway runs headless with the pixman renderer and needs no GPU; the image's `mikan-desktop` script starts it and is the only in-container contract. wayvnc serves WebSocket itself, at most 60 fps, and leaves the pointer to the client. While the desktop is up, `jev_browser` launches Chromium headed on Wayland (`AGENT_BROWSER_HEADED`, `--ozone-platform=wayland`); without the desktop it stays headless, because a headed launch fails when no compositor is running.
- **Access.** Like `/session`, a member of the conversation asks for a link and receives it privately; a shared conversation on a platform without private replies is told to ask in a direct message. As with `/session` and `/admin` links, the token is a bearer token: it is issued to the person who asked, names one office, and expires after 24 hours, and whoever holds the link can use it until then; it cannot be revoked. The desktop belongs to the office's Sandbox runtime, so Office visibility, which governs only what other offices may read, does not apply; a link never reaches another office's desktop.
- **Transport.** mikan's web server serves the noVNC client and forwards one WebSocket per viewer to wayvnc inside the container through `<engine> exec -i`, the same path as the pi-env connection. No container port is published. An open viewer counts as use of the container, so the container is not stopped while someone is watching.
- **Browser control.** Modeled on ego-browser: the agent owns the browser by default and a person may watch. A person who takes control stops `jev_browser`, which reports that the person has control and does not retry. The agent may hand control to the person, explaining the step and posting the link, and end its round; a page the agent opened headless is reopened on the desktop first, as the only tab and without its cookies. Hand-off works only in direct messages, where the link can be sent privately. It resumes after the person hands control back, and control returns to the agent 10 seconds after the last viewer disconnects. The agent never closes a tab a person opened. Control covers the browser only, not other commands in the sandbox.
- **Mobile** is out of scope for now: a phone can view the desktop and tap, but the soft keyboard does not open.

## Consequences

- A thread whose browser started headless before the desktop came up keeps it until the browser restarts or the agent hands off, which reopens the page on the desktop without its cookies.
- The web server serves noVNC from `@novnc/novnc` (MPL-2.0, 0.6 MB, no dependencies).
- Every image is 3 MB larger; an office pays the desktop's memory only while its desktop runs.
- Desktop links share the portal token model of `/session` and `/admin`; making links bound to a signed-in person and revocable is left to a later change to that model for every portal.
- A member with a link can operate the whole sandbox, including credentials mounted from the Vault. Members could already make the agent do so; the link turns indirect control into direct control.
- Host and existing-container sandbox modes have no managed container to start the desktop in; the link command reports that.
- VNC sends changed pixels, so video-heavy pages cost more bandwidth than a video stream would. KasmVNC and Selkies stream video but replace wayvnc.
Loading
Loading
0