跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

guest-services.sh

154 行 · 6.6 KB历史下载
1# Publish browser assets while the web endpoint is stopped, so clients cannot
2# mix old and new noVNC modules during an upgrade.
3if systemctl is-active --quiet cage-webvnc; then
4 sudo systemctl stop cage-webvnc
5fi
6if ! command -v X0tigervnc >/dev/null || ! command -v Xtigervnc >/dev/null || ! command -v openbox >/dev/null || ! command -v xrandr >/dev/null || ! command -v xdotool >/dev/null || ! command -v ibus-daemon >/dev/null || ! /usr/bin/python3 -c 'import gi; gi.require_version("IBus", "1.0"); gi.require_version("Gtk", "3.0")' 2>/dev/null; then
7 sudo env DEBIAN_FRONTEND=noninteractive APT_CONFIG="${CAGE_APT_CONFIG:-/dev/null}" apt-get install -y --no-install-recommends tigervnc-standalone-server tigervnc-scraping-server tigervnc-tools openbox x11-xserver-utils xdotool libgtk-3-0 ibus ibus-gtk3 gir1.2-ibus-1.0 gir1.2-gtk-3.0 python3-gi python3-xlib xsettingsd
8fi
9cage_novnc_root=/usr/share/novnc
10if cage_is_ubuntu; then
11 cage_install_ubuntu_novnc
12 cage_novnc_root=/usr/local/share/cage-novnc
13fi
14sudo install -d -m 0755 /usr/local/share
15sudo ln -sfn "$cage_novnc_root" /usr/local/share/cage-webvnc
16sudo install -d -m 0755 /etc/claude-cage /usr/local/lib
17# New website passwords belong to the host vault. Keep existing browser data.
18cage_browser_policy_dir=/etc/chromium/policies/managed
19if cage_is_ubuntu; then cage_browser_policy_dir=/etc/opt/chrome_for_testing/policies/managed; fi
20sudo install -d -m 0755 "$cage_browser_policy_dir"
21printf '%s\n' '{"PasswordManagerEnabled":false}' | sudo tee "$cage_browser_policy_dir/cage-password-vault.json" >/dev/null
22sudo chmod 0644 "$cage_browser_policy_dir/cage-password-vault.json"
23sudo tee /usr/local/bin/cage-editor-start >/dev/null <<'SCRIPT'
24#!/bin/sh
25set -eu
26workspace=$(cat /home/cage/.config/claude-cage/editor-workspace)
27exec /usr/bin/code-server --bind-addr 127.0.0.1:18080 --config /home/cage/.config/claude-cage/code-server.yaml --disable-telemetry --disable-update-check --disable-workspace-trust --disable-proxy "$workspace"
28SCRIPT
29sudo chmod 0755 /usr/local/bin/cage-editor-start
30sudo tee /etc/systemd/system/cage-editor.service >/dev/null <<'UNIT'
31[Unit]
32Description=Cage file editor
33[Service]
34User=cage
35WorkingDirectory=/home/cage
36Environment=HOME=/home/cage
37EnvironmentFile=/etc/claude-cage/environment
38ExecStart=/usr/local/bin/cage-log-run /usr/local/bin/cage-editor-start
39LogNamespace=cage
40Restart=on-failure
41RestartSec=2
42TimeoutStopSec=15
43UNIT
44printf 'cage-browser ALL=(root) NOPASSWD: /usr/bin/systemctl restart cage-editor.service\n' | sudo tee /etc/sudoers.d/cage-editor >/dev/null
45sudo chmod 0440 /etc/sudoers.d/cage-editor
46sudo tee /etc/profile.d/claude-cage.sh >/dev/null <<'SCRIPT'
47if [ -f /etc/claude-cage/environment ]; then
48 set -a
49 . /etc/claude-cage/environment
50 set +a
51fi
52unset HTTP_PROXY HTTPS_PROXY ALL_PROXY FTP_PROXY NO_PROXY http_proxy https_proxy all_proxy ftp_proxy no_proxy
53export BROWSER=/usr/local/bin/cage-open
54SCRIPT
55if ! grep -q '/etc/profile.d/claude-cage.sh' /etc/zsh/zshenv; then
56 echo '. /etc/profile.d/claude-cage.sh' | sudo tee -a /etc/zsh/zshenv >/dev/null
57fi
58sudo tee /etc/systemd/system/cage-display.service >/dev/null <<'UNIT'
59[Unit]
60Description=Claude Cage virtual browser display
61Wants=cage-display-governor.service
62[Service]
63User=cage-browser
64ExecStartPre=/usr/bin/rm -f /home/cage-browser/.vnc/display.sock
65ExecStart=/usr/local/bin/cage-log-run /usr/bin/Xtigervnc :77 -geometry 2880x1800 -depth 24 -rfbport -1 -rfbunixpath /home/cage-browser/.vnc/display.sock -rfbunixmode 0600 -nolisten tcp -localhost -SecurityTypes VncAuth -PasswordFile /home/cage-browser/.vnc/passwd
66LogNamespace=cage
67Restart=on-failure
68UNIT
69sudo tee /etc/claude-cage/openbox.xml >/dev/null <<'WINDOW_CONFIG'
70<?xml version="1.0" encoding="UTF-8"?>
71<openbox_config xmlns="http://openbox.org/3.4/rc">
72<focus><focusNew>yes</focusNew><followMouse>no</followMouse></focus>
73<desktops><number>1</number></desktops>
74<keyboard></keyboard><mouse></mouse>
75<applications><application type="normal"><decor>no</decor><maximized>yes</maximized></application></applications>
76</openbox_config>
77WINDOW_CONFIG
78sudo tee /etc/systemd/system/cage-window-manager.service >/dev/null <<'UNIT'
79[Unit]
80Description=Cage window geometry and focus (no desktop shell)
81Requires=cage-display.service
82After=cage-display.service
83[Service]
84User=cage-browser
85Environment=DISPLAY=:77
86ExecStart=/usr/local/bin/cage-log-run /usr/bin/openbox --config-file /etc/claude-cage/openbox.xml
87LogNamespace=cage
88Restart=on-failure
89UNIT
90sudo tee /etc/systemd/system/cage-browser.service >/dev/null <<'UNIT'
91[Unit]
92Description=Claude Cage persistent browser
93Requires=cage-display.service cage-window-manager.service
94After=cage-display.service cage-window-manager.service
95[Service]
96User=cage-browser
97Environment=DISPLAY=:77
98EnvironmentFile=/etc/claude-cage/environment
99ExecStart=/usr/local/bin/cage-log-run /usr/local/bin/cage-input-session /usr/bin/node /usr/local/lib/cage-browser-agent.mjs
100LogNamespace=cage
101# Let the controller close Chromium and flush its tabs and profile before
102# systemd terminates any remaining child processes.
103KillMode=mixed
104Restart=on-failure
105RestartSec=2
106UNIT
107# Starts, restarts and stops with the display it paces. The display only
108# wants it: a guest without python3-xlib keeps its full refresh rate.
109sudo tee /etc/systemd/system/cage-display-governor.service >/dev/null <<'UNIT'
110[Unit]
111Description=Claude Cage browser display pacing
112PartOf=cage-display.service
113After=cage-display.service
114[Service]
115User=cage-browser
116Environment=DISPLAY=:77
117ExecStart=/usr/local/bin/cage-log-run /usr/local/bin/cage-display-governor
118LogNamespace=cage
119Restart=on-failure
120RestartSec=5
121UNIT
122sudo tee /etc/systemd/system/cage-vnc.service >/dev/null <<'UNIT'
123[Unit]
124Description=Claude Cage browser screen
125Requires=cage-display.service
126After=cage-display.service
127[Service]
128User=cage-browser
129ExecStart=/usr/local/bin/cage-log-run /usr/bin/X0tigervnc -display :77 -rfbport 15900 -localhost -SecurityTypes VncAuth -PasswordFile /home/cage-browser/.vnc/passwd -AlwaysShared
130LogNamespace=cage
131Restart=on-failure
132RestartSec=2
133UNIT
134sudo tee /etc/systemd/system/cage-webvnc.service >/dev/null <<'UNIT'
135[Unit]
136Description=Claude Cage browser web access
137Requires=cage-vnc.service
138After=cage-vnc.service
139[Service]
140User=cage-browser
141ExecStart=/usr/local/bin/cage-log-run /usr/bin/websockify --web=/usr/local/share/cage-webvnc 127.0.0.1:16080 127.0.0.1:15900
142LogNamespace=cage
143Restart=on-failure
144UNIT
145sudo systemctl daemon-reload
146
147if ! grep -q 'CAGE_WORKBENCH_PROMPT' /home/cage/.bashrc; then
148 sudo tee -a /home/cage/.bashrc >/dev/null <<'PROMPT'
149# CAGE_WORKBENCH_PROMPT
150if [ "${CAGE_WORKBENCH:-}" = 1 ]; then
151 PS1='\[\e[32m\]cage\[\e[0m\]:\[\e[34m\]\W\[\e[0m\]\$ '
152fi
153PROMPT
154fi