Skip to content

OpenClaw 在 macOS 虚拟机中运行(沙盒隔离)

推荐方案(大多数用户)

  • 小型 Linux VPS:持续运行、低成本的 Gateway 首选。参见 VPS 托管
  • 专用硬件(Mac mini 或 Linux 主机):需要完全控制,且需要住宅 IP 做浏览器自动化时使用。许多网站会封锁数据中心 IP,本地浏览往往效果更好。
  • 混合方案:Gateway 放在廉价 VPS,需要浏览器/UI 自动化时把 Mac 作为节点接入。参见 NodesGateway 远程访问

只有当你确实需要 macOS 专属功能(iMessage/BlueBubbles)或需要与日常 Mac 环境严格隔离时,才考虑 macOS VM 方案。

macOS VM 选项

在苹果芯片 Mac 上运行本地 VM(Lume)

Lume 在你现有的苹果芯片 Mac 上运行沙盒化的 macOS VM,把龙虾关进隔离箱。

你将获得:

  • 完全隔离的 macOS 环境(宿主机保持干净)
  • 通过 BlueBubbles 支持 iMessage(Linux/Windows 无法实现)
  • 通过克隆 VM 实现秒级重置
  • 无需额外硬件或云费用

云端托管 Mac(远程)

如果需要在云端运行 macOS,托管 Mac 服务商也可以:

  • MacStadium(托管 Mac)
  • 其他托管 Mac 服务商也可以;按其 VM + SSH 文档操作

有了 macOS VM 的 SSH 访问权限后,直接跳到下面的第 6 步。


快速路径(Lume,有经验的用户)

  1. 安装 Lume
  2. lume create openclaw --os macos --ipsw latest
  3. 完成设置助手,启用远程登录(SSH)
  4. lume run openclaw --no-display
  5. SSH 进入,安装 OpenClaw,配置渠道
  6. 完成

所需条件(Lume)

  • 苹果芯片 Mac(M1/M2/M3/M4)
  • 宿主机运行 macOS Sequoia 或更高版本
  • 每个 VM 约需 60GB 可用磁盘空间
  • 约 20 分钟

1) 安装 Lume

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/lume/scripts/install.sh)"

如果 ~/.local/bin 不在 PATH 中:

bash
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.zshrc && source ~/.zshrc

验证:

bash
lume --version

文档:Lume 安装指南


2) 创建 macOS VM

bash
lume create openclaw --os macos --ipsw latest

这会下载 macOS 并创建 VM,自动打开 VNC 窗口。

注意:下载时间取决于你的网速,可能需要一段时间。


3) 完成设置助手

在 VNC 窗口中:

  1. 选择语言和地区
  2. 跳过 Apple ID(如果以后需要 iMessage 可以登录)
  3. 创建用户账号(记住用户名和密码)
  4. 跳过所有可选功能

设置完成后,启用 SSH:

  1. 打开系统设置 → 通用 → 共享
  2. 开启"远程登录"

4) 获取 VM IP 地址

bash
lume get openclaw

找到 IP 地址(通常是 192.168.64.x)。


5) SSH 进入 VM

bash
ssh youruser@192.168.64.X

youruser 替换为你创建的账号,IP 替换为你 VM 的 IP。


6) 安装 OpenClaw

在 VM 内:

bash
npm install -g openclaw@latest
openclaw onboard --install-daemon

按引导提示设置模型提供商(Anthropic、OpenAI 等)。


7) 配置渠道

编辑配置文件:

bash
nano ~/.openclaw/openclaw.json

添加你的渠道:

json5
{
  channels: {
    whatsapp: {
      dmPolicy: "allowlist",
      allowFrom: ["+15551234567"],
    },
    telegram: {
      botToken: "YOUR_BOT_TOKEN",
    },
  },
}

然后登录 WhatsApp(扫二维码):

bash
openclaw channels login

8) 无显示模式运行 VM

停止 VM 后以无头模式重启:

bash
lume stop openclaw
lume run openclaw --no-display

VM 在后台运行,OpenClaw 的守护进程保持 Gateway 运行。

检查状态:

bash
ssh youruser@192.168.64.X "openclaw status"

番外:iMessage 集成

这是在 macOS 上运行的杀手级功能。使用 BlueBubbles 为 OpenClaw 添加 iMessage 支持。

在 VM 内:

  1. 从 bluebubbles.app 下载 BlueBubbles
  2. 用你的 Apple ID 登录
  3. 启用 Web API 并设置密码
  4. 将 BlueBubbles Webhook 指向你的 Gateway(例如:https://your-gateway-host:3000/bluebubbles-webhook?password=<password>

在 OpenClaw 配置中添加:

json5
{
  channels: {
    bluebubbles: {
      serverUrl: "http://localhost:1234",
      password: "your-api-password",
      webhookPath: "/bluebubbles-webhook",
    },
  },
}

重启 Gateway 后,你的 Agent 就能收发 iMessage 了。

完整配置详情:BlueBubbles 渠道


保存黄金镜像

在进一步自定义前,先快照一个干净状态:

bash
lume stop openclaw
lume clone openclaw openclaw-golden

随时可以重置:

bash
lume stop openclaw && lume delete openclaw
lume clone openclaw-golden openclaw
lume run openclaw --no-display

7×24 运行

保持 VM 持续运行的方法:

  • Mac 保持充电状态
  • 在系统设置 → 节能中禁用睡眠
  • 必要时使用 caffeinate 命令

想要真正全天候运行,考虑专用 Mac mini 或小型 VPS。参见 VPS 托管


故障排查

问题解决方法
无法 SSH 进入 VM检查 VM 系统设置中"远程登录"是否已开启
VM IP 不显示等待 VM 完全启动后,再次运行 lume get openclaw
找不到 lume 命令~/.local/bin 添加到 PATH
WhatsApp 二维码无法扫描确保在 VM 内(而非宿主机)运行 openclaw channels login

相关文档