|
| 1 | +schemaVersion: "2" |
| 2 | +kind: mixin |
| 3 | +name: vscode |
| 4 | +displayName: Visual Studio Code (native, via --display) |
| 5 | +description: Installs VS Code from Microsoft's apt repository and starts it as a Wayland client on the host desktop, opening the sandbox workspace. Requires `--display` at sandbox creation time and the `feature.sandbox-display` feature flag — see the README. |
| 6 | +permissions: |
| 7 | + network: |
| 8 | + allow: |
| 9 | + # setup.install runs apt-get update, which refreshes every configured |
| 10 | + # apt source. The claude-code-docker base template pre-configures |
| 11 | + # Docker's apt repo, so download.docker.com must be allowed even though |
| 12 | + # this kit doesn't install anything from it — apt-get exits 100 on the |
| 13 | + # first source metadata fetch that returns non-2xx. Ubuntu hosts amd64 |
| 14 | + # packages on archive/security and arm64 packages on ports.ubuntu.com, |
| 15 | + # so all three Ubuntu hosts are listed for cross-arch coverage. |
| 16 | + - archive.ubuntu.com |
| 17 | + - security.ubuntu.com |
| 18 | + - ports.ubuntu.com |
| 19 | + - download.docker.com |
| 20 | + # Install-time: Microsoft's apt repo (signing key + .deb). |
| 21 | + - packages.microsoft.com |
| 22 | + # Runtime: VS Code's own update / telemetry / download endpoints. |
| 23 | + - update.code.visualstudio.com |
| 24 | + - vscode.download.prss.microsoft.com |
| 25 | + # Extensions: marketplace + CDN. |
| 26 | + - marketplace.visualstudio.com |
| 27 | + - "*.vscode-cdn.net" |
| 28 | + - "*.gallerycdn.vsassets.io" |
| 29 | +agentInstructions: |
| 30 | + content: | |
| 31 | + ## VS Code |
| 32 | +
|
| 33 | + VS Code is running inside this sandbox. Its window is visible on the |
| 34 | + host desktop — it opened the sandbox workspace on startup, so any |
| 35 | + file you create or edit in the terminal is immediately visible in the |
| 36 | + editor, and vice versa. |
| 37 | +
|
| 38 | + If the user closes the VS Code window and wants to reopen it, run |
| 39 | + `code &` from any terminal inside the sandbox. |
| 40 | +
|
| 41 | + If the VS Code window is not visible at all, check that `--display` |
| 42 | + was passed at sandbox creation time and that the host compositor is |
| 43 | + running. The process runs backgrounded; it does not produce a log |
| 44 | + file by default. |
| 45 | +setup: |
| 46 | + install: |
| 47 | + - command: | |
| 48 | + set -euo pipefail |
| 49 | +
|
| 50 | + # apt's InRelease verification uses O_TMPFILE, which is incompatible |
| 51 | + # with the virtiofs overlay backing the container. Route the lists |
| 52 | + # directory through /dev/shm (a plain tmpfs) instead. The .deb cache |
| 53 | + # stays at its default location (/var/cache/apt/archives) because |
| 54 | + # /dev/shm's 64 MiB ceiling is too small for the full package set. |
| 55 | + mkdir -p /dev/shm/apt-lists |
| 56 | + APT_OPTS="-o DPkg::Lock::Timeout=600 -o Dir::State::Lists=/dev/shm/apt-lists" |
| 57 | + export TMPDIR=/dev/shm |
| 58 | +
|
| 59 | + apt-get $APT_OPTS update |
| 60 | + apt-get $APT_OPTS install -yy --no-install-recommends ca-certificates curl gnupg |
| 61 | +
|
| 62 | + install -d -m 0755 /usr/share/keyrings |
| 63 | + curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \ |
| 64 | + | gpg --dearmor > /usr/share/keyrings/packages.microsoft.gpg |
| 65 | + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" \ |
| 66 | + > /etc/apt/sources.list.d/vscode.list |
| 67 | +
|
| 68 | + apt-get $APT_OPTS update |
| 69 | + apt-get $APT_OPTS install -yy --no-install-recommends code dbus-x11 |
| 70 | +
|
| 71 | + rm -rf /dev/shm/apt-lists |
| 72 | + apt-get clean |
| 73 | + user: "0" |
| 74 | + description: | |
| 75 | + Install Visual Studio Code from Microsoft's official APT repository, |
| 76 | + plus dbus-x11 (which provides dbus-run-session, needed by Electron to |
| 77 | + wire its IPC bus when no session bus is present in the container). |
| 78 | +
|
| 79 | + files: |
| 80 | + - path: /home/agent/.local/bin/code |
| 81 | + mode: "0755" |
| 82 | + description: Launch wrapper written at each startup so WORKSPACE_DIR is resolved at runtime. |
| 83 | + content: | |
| 84 | + #!/bin/sh |
| 85 | + if [ ! -S /run/display/wayland-0 ]; then |
| 86 | + echo "code: display socket not found at /run/display/wayland-0" >&2 |
| 87 | + echo "This sandbox was not created with --display." >&2 |
| 88 | + echo "" >&2 |
| 89 | + echo "To fix, enable the experimental display feature and recreate:" >&2 |
| 90 | + echo " sbx settings set platform.allowExperimentalFeatures true" >&2 |
| 91 | + echo " sbx settings set feature.sandbox-display true" >&2 |
| 92 | + echo " sbx run claude --display --kit <this-kit> <workspace>" >&2 |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + export WAYLAND_DISPLAY=/run/display/wayland-0 |
| 96 | + HOME_DIR=$(getent passwd 1000 | cut -d: -f6) |
| 97 | + if [ -z "$HOME_DIR" ]; then |
| 98 | + echo "code: no user at uid 1000" >&2 |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + export HOME="$HOME_DIR" |
| 102 | + LAUNCH_DIR="$WORKSPACE_DIR" |
| 103 | + if [ -z "$LAUNCH_DIR" ]; then LAUNCH_DIR="$HOME_DIR"; fi |
| 104 | + exec dbus-run-session /usr/share/code/code \ |
| 105 | + --ozone-platform=wayland \ |
| 106 | + --disable-gpu \ |
| 107 | + --disable-gpu-compositing \ |
| 108 | + --no-sandbox \ |
| 109 | + --disable-dev-shm-usage \ |
| 110 | + --user-data-dir="$HOME_DIR/.vscode-user" \ |
| 111 | + "$LAUNCH_DIR" |
| 112 | +
|
| 113 | + startup: |
| 114 | + - command: |
| 115 | + - setpriv |
| 116 | + - --reuid=1000 |
| 117 | + - --regid=1000 |
| 118 | + - --init-groups |
| 119 | + - /home/agent/.local/bin/code |
| 120 | + user: "0" |
| 121 | + background: true |
| 122 | + description: | |
| 123 | + Launch VS Code as a Wayland client opening the sandbox's workspace. |
| 124 | + Runs as root then drops to uid 1000 via setpriv. The window appears |
| 125 | + on the host compositor via the display surface provisioned by |
| 126 | + --display. Backgrounded so the agent's terminal keeps focus. |
0 commit comments