跳到主要内容

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

提交记录

Merge pull request #17 from benoitvx/chore/agent-vm-mount-guardrails

Add mount guard-rails to prevent silent VM mount failures

作者
Sylvain Zimmer
时间
2026/06/30 01:27
提交
e039eee
这个版本的全部文件

这是一个合并提交,下面是和第一个上一提交相比的改动。

修改agent-vm.sh+52 −2看文件
@@ -77,6 +77,17 @@ _agent_vm_ensure_running() {
7777 esac
7878 done
7979
80新增: # Lima's host mount cannot share a path containing whitespace: the mount
81新增: # fails silently and the VM starts with a bare, root-owned mountpoint, so
82新增: # every write into the project (e.g. creating .claude) fails with
83新增: # "Permission denied". Fail fast with an actionable message instead.
84新增: if [[ "$host_dir" == *[[:space:]]* ]]; then
85新增: echo "Error: project path contains whitespace, which Lima cannot mount:" >&2
86新增: echo " $host_dir" >&2
87新增: echo "Rename the directory to remove spaces (e.g. with '-'), then retry." >&2
88新增: return 1
89新增: fi
90新增:
8091 if ! limactl list -q 2>/dev/null | grep -q "^${AGENT_VM_TEMPLATE}$"; then
8192 echo "Error: Base VM not found. Run 'agent-vm setup' first." >&2
8293 return 1
@@ -158,6 +169,32 @@ _agent_vm_ensure_running() {
158169 limactl start "$vm_name" &>/dev/null
159170 fi
160171
172新增: # Sanity-check that the project directory is actually shared and writable.
173新增: # A silently-failed or stale mount leaves a bare, root-owned mountpoint;
174新增: # without this check every later write (runtime scripts, the agent itself)
175新增: # fails with a confusing cascade of "Permission denied" instead of one clear
176新增: # error. Runs before the optional --readonly remount below, so it reflects
177新增: # the mount itself, not the requested read-only restriction.
178新增: #
179新增: # If the mount is broken, try to self-heal once: re-apply the mount config
180新增: # (Lima only allows editing a stopped VM) and restart. This repairs a stale
181新增: # or silently-missing mount without forcing a full --reset, and adds no
182新增: # overhead on the common path where the mount is already healthy.
183新增: if ! limactl shell "$vm_name" test -w "$host_dir" &>/dev/null; then
184新增: echo "Project mount is not writable; repairing..." >&2
185新增: limactl stop "$vm_name" &>/dev/null
186新增: (cd /tmp && limactl edit "$vm_name" \
187新增: --set ".mounts = [{\"location\": \"${host_dir}\", \"writable\": true}]") &>/dev/null
188新增: limactl start "$vm_name" &>/dev/null
189新增: if ! limactl shell "$vm_name" test -w "$host_dir" &>/dev/null; then
190新增: echo "Error: project directory is still not writable inside the VM:" >&2
191新增: echo " $host_dir" >&2
192新增: echo "The host mount failed to attach. Try 'agent-vm --reset <command>'" >&2
193新增: echo "to re-clone the VM from the base template." >&2
194新增: return 1
195新增: fi
196新增: fi
197新增:
161198 # Install the host's terminfo entry inside the VM so non-standard terminals
162199 # (xterm-ghostty, xterm-kitty, …) work correctly. Without this, zsh/ZLE
163200 # can't decode keys → broken backspace, arrows, etc. Cached per-VM so we only
@@ -242,6 +279,19 @@ agent-vm() {
242279 local cmd="${1:-help}"
243280 shift 2>/dev/null || true
244281
282新增: # Every command except help/setup needs limactl present. (setup installs it
283新增: # itself; help needs nothing.) Without this, stop/list/status/etc. would fail
284新增: # with confusing empty output instead of a clear, actionable message.
285新增: case "$cmd" in
286新增: help|--help|-h|setup) ;;
287新增: *)
288新增: if ! command -v limactl &>/dev/null; then
289新增: echo "Error: limactl (Lima) not found. Run 'agent-vm setup' first, or install" >&2
290新增: echo "it from https://lima-vm.io/docs/installation/" >&2
291新增: return 1
292新增: fi ;;
293新增: esac
294新增:
245295 case "$cmd" in
246296 setup)
247297 _agent_vm_setup "${vm_opts[@]}" "$@"
@@ -307,7 +357,7 @@ Commands:
307357
308358VM options (for claude, opencode, codex, shell, run):
309359 --disk GB VM disk size (default: 10)
310删除: --memory GB VM memory (default: 2)
360新增: --memory GB VM memory (default: 3)
311361 --cpus N Number of CPUs (default: 1)
312362 --reset Destroy and re-clone the VM from the base template
313363 --offline Block outbound internet (keeps host/VM communication)
@@ -356,7 +406,7 @@ _agent_vm_setup() {
356406 echo ""
357407 echo "Options:"
358408 echo " --disk GB VM disk size (default: 10)"
359删除: echo " --memory GB VM memory (default: 2)"
409新增: echo " --memory GB VM memory (default: 3)"
360410 echo " --cpus N Number of CPUs (default: 1)"
361411 echo " --help Show this help"
362412 return 0