從零開始在你的機器上養一隻 AI 龍蝦——安裝、設定、連線、強化,一篇搞定
OpenClaw(前身 Clawdbot → Moltbot → OpenClaw)是一個開源、自架的 AI Agent 運行時。把它想像成一隻「寵物龍蝦」——你在自己的機器上養牠,餵牠 LLM API Key,然後透過你日常使用的通訊軟體(Telegram、WhatsApp、Slack、Discord、iMessage 等 25+ 平台)與牠對話。牠不只會聊天,還會幫你操作檔案、跑程式、管理行事曆、發 Email——真正的 24/7 自主 Agent。
截至 2026 年 3 月,OpenClaw 在 GitHub 上擁有 190K+ stars,是史上成長最快的開源專案之一。目前由開源基金會維護(創辦人 Peter Steinberger 已加入 OpenAI)。
整個系統的核心是 Gateway——一個持續運行的背景程式。所有訊息進出都經過 Gateway,它負責排隊、分派給 Agent、再把回應送回正確的 channel。所有狀態寫入本地 ~/.openclaw 目錄,用的是 Markdown 檔案,不是資料庫。
| 項目 | 需求 | 備註 |
|---|---|---|
| Node.js | v22.16+ 或 v24(推薦) | node --version 確認 |
| 作業系統 | macOS / Linux / Windows (WSL2) | WSL2 比原生 Windows 穩定 |
| LLM API Key | Anthropic / OpenAI / Google 擇一 | 2026 年起 OAuth 已關閉,必須用 API Key |
| 硬體 | 2GB+ RAM, 1+ vCPU | Mac mini / VPS $5/月 即可 |
| 通訊平台 | Telegram(推薦入門) | @BotFather 建 bot、取得 token |
| One-Liner | npm | Docker | |
|---|---|---|---|
| 指令 | curl ... | bash | npm i -g openclaw | docker compose up |
| 需要 Node.js | 自動安裝 | 需自備 | 不需要 |
| 沙箱隔離 | ❌ | ❌ | ✅ |
| 升級方式 | openclaw update | npm i -g openclaw@latest | 改 image tag |
| 適合 | 本地測試 | 開發者 | 生產環境 / VPS |
Terminal# 方法一:One-Liner(推薦) curl -fsSL https://openclaw.ai/install.sh | bash # 方法二:npm npm install -g openclaw@latest # 確認安裝 openclaw --version # 應顯示 v2026.3.x
Terminalopenclaw onboard
Wizard 會依序引導你:選 AI Provider → 輸入 API Key → 設定 Gateway Token → 連接訊息平台。整個過程約 2 分鐘。
Terminal# 前景執行(開發用) openclaw gateway run # 或安裝為 Daemon(推薦) openclaw onboard --install-daemon
Gateway 啟動後會監聽 port 18789。在瀏覽器開啟 Control UI:http://localhost:18789
大多數教學到步驟 3 就停了。但這是最危險的時刻——你的 Gateway 可能暴露在區域網路上。往下看第 7 節完成安全強化。
第一則訊息"嗨,我們來設定你吧。請讀 BOOTSTRAP.md 並引導我完成設定。"
這是你給 Agent 發的第一則訊息。它會建立 Agent 身份、填入 USER.md、設定偏好。務必在問任何正式問題之前先做。
Terminal# CLI 直接對話 openclaw run "列出今天的日期,以及我的機器作業系統版本" # 或從 Telegram / WhatsApp 傳訊息
| 平台 | 連線方式 | 推薦度 |
|---|---|---|
| Telegram | @BotFather 建 bot → 貼 token 到 Settings | ⭐⭐⭐ 最推薦入門 |
| 掃 QR Code 配對(WhatsApp Business API) | ⭐⭐⭐ 日常最方便 | |
| Slack | Slack App + Bot Token | ⭐⭐ 團隊使用 |
| Discord | Discord Bot Token | ⭐⭐ 社群使用 |
| iMessage | 需 macOS + BlueBubbles | ⭐ 進階設定 |
| Signal / Teams / Google Chat | 各自的 Bot API / Webhook | ⭐ 依需求 |
所有 channel 在 Onboarding 或 Control UI 的 Settings 中設定。一個 OpenClaw 實例可以同時連接多個平台。
這是影響最大的單一設定。將 Gateway 綁到 loopback,阻擋所有外部連線。
~/.openclaw/openclaw.json{ "gateway": { "mode": "local", "bind": "loopback", "port": 18789 } }
Terminal# 產生 32 字元隨機 token openssl rand -hex 32
openclaw.json{ "gateway": { "auth": { "mode": "token", "token": "你產生的-32-字元-隨機-token" } } }
OpenClaw 預設會透過 mDNS 廣播自己的存在。關掉它:
openclaw.json{ "gateway": { "mdns": { "enabled": false } } }
Terminalchmod 700 ~/.openclaw
chmod 600 ~/.openclaw/openclaw.json
chmod -R 600 ~/.openclaw/credentials/
openclaw.json{ "tools": { "profile": "messaging", "deny": ["group:automation", "group:runtime", "group:fs"], "fs": { "workspaceOnly": true }, "exec": { "security": "deny", "ask": "always" }, "elevated": { "enabled": false } } }
openclaw.json{ "session": { "dmScope": "per-channel-peer" }, "channels": { "whatsapp": { "dmPolicy": "pairing", "groups": { "*": { "requireMention": true } } } } }
Terminal# 基本審計 openclaw security audit # 深度審計(含 Skill 惡意程式掃描) openclaw security audit --deep # 自動修復常見問題 openclaw security audit --fix
| 規則 | 做法 |
|---|---|
| 安裝前必查 | clawhub inspect <slug> 看 VirusTotal 報告 |
| 100/3 規則 | 只安裝 100+ 下載量且存在 3+ 個月的 Skill |
| 權限審查 | 如果 weather skill 要求 shell 存取——那是紅旗 |
| 原始碼審查 | 在 GitHub 上讀 SKILL.md 和附帶的腳本 |
| 白名單制度 | 用 tools.allow 明確列出允許的工具,而不是用 deny |
| 先沙箱測試 | 新 Skill 先在 Docker 容器中跑,確認安全再部署到主機 |
OpenClaw 比直接用 Claude.ai 聊天消耗多 5-10 倍 token——因為每個任務會觸發多次 API 呼叫(檔案讀寫、工具執行、推理、修正),而且每次呼叫都會重送完整對話 context。
| 使用模式 | 模型 | 月費估算 |
|---|---|---|
| 輕度(日常對話、行事曆) | Claude Sonnet | $3 – $10/月 |
| 中度(程式碼、研究、自動化) | Claude Sonnet | $30 – $80/月 |
| 重度(全天候 Agent、多任務) | Claude Opus 4.6 | $100 – $200+/月 |
| 省錢方案 | OpenRouter 免費模型 | $0(heartbeat/sub-agent 用) |
| CVE | 嚴重度 | 說明 | 修補版本 |
|---|---|---|---|
| CVE-2026-25253 | Critical (8.8) | 一鍵 RCE:惡意網頁可竊取 Gateway token,透過 WebSocket 取得完整控制 | v2026.1.29+ |
| CVE-2026-24763 | High | Command Injection:未正確消毒的 input 允許任意指令注入 | v2026.2.x+ |
| CVE-2026-25157 | High | Command Injection(第二個):另一個注入向量 | v2026.2.x+ |
| CVE-2026-22708 | Medium | Indirect Prompt Injection:瀏覽器擷取的網頁可含隱藏指令 | 緩解措施(非完全修復) |
v2026.3.11。跑 openclaw update 升級,再跑 openclaw doctor --fix 遷移設定。
| 問題 | 解法 |
|---|---|
| Port 18789 already in use | ps aux | grep openclaw 找殭屍程式 → killall -9 node → openclaw gateway run --force |
| npm install 失敗 / command not found | 確認 Node.js ≥ 22.16(node -v)。重啟 terminal 或加全域 npm bin 到 PATH |
| Control UI 打不開 | 確認 Gateway 正在跑。如果綁了 loopback,必須從同一台機器的瀏覽器開 |
| Token Mismatch | openclaw devices clear --yes --all → 重新從 openclaw.json 取 token → 重新配對 |
| API 404 / 模型不存在 | 舊模型可能已棄用(如 grok-beta)。openclaw config set agents.defaults.model.primary "模型名稱" |
| Telegram 回覆慢 | ISP 路由問題。用 Cloudflare WARP 或 WARP Local Proxy 模式加速 |
| Docker 連不到 Gateway | 用 host.docker.internal 取代 127.0.0.1 |
| Skill 安裝後異常 | openclaw security audit --deep 掃描 → 對照 ClawHub VirusTotal 報告 |
直接貼入 Claude Code,自動完成安裝、設定、安全強化: