本地虚拟机沙箱一键启动 ClawdBot/MoltBot,再也不用担心 AI 删库跑路了~

1 月 30 日
 d0r1an
#!/usr/bin/env python3
import asyncio
import os
import sys

async def main():
    print("Starting MoltBot in micro-VM sandbox...")
    print("Type 'exit' or press Ctrl+D to quit\n")
    try:
        from boxlite import InteractiveBox
        term_mode = os.environ.get("TERM", "xterm-256color")
        async with InteractiveBox(name="moltbox", image="ubuntu:26.04", env=[("TERM", term_mode)], ports=[(18789, 18789)], auto_remove=False, reuse_existing=True) as itbox:
            await itbox.wait()
    except KeyboardInterrupt:
        print("\n\nInterrupted by Ctrl+C")
    except Exception as e:
        print(f"\nError: {e}", file=sys.stderr)
        import traceback
        traceback.print_exc()
        sys.exit(1)

if __name__ == "__main__":
    asyncio.run(main())
  apt-get update -y
  apt-get install -y --no-install-recommends curl ca-certificates
  curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
  apt-get install -y nodejs

  Or the full updated script for Ubuntu:

  #!/bin/sh
  set -e
  export DEBIAN_FRONTEND=noninteractive
  export PATH=/usr/local/bin:$PATH

  # --- Install Node.js + clawdbot if missing ---
  if ! command -v clawdbot >/dev/null 2>&1; then
    apt-get update -y
    apt-get install -y --no-install-recommends python3 make g++ git ca-certificates curl lsof
    curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
    apt-get install -y nodejs
    npm config set cache /tmp/npm-cache
    npm install -g clawdbot@latest
  fi

  # --- Configure & start gateway ---
  set -eu
  CONF_DIR=/root/.clawdbot
  mkdir -p "$CONF_DIR"

  BIN=$(command -v clawdbot || true)
  if [ -z "$BIN" ]; then
    BIN="$(npm bin -g)/clawdbot"
  fi

  export CLAWDBOT_STATE_DIR="$CONF_DIR"
  export CLAWDBOT_CONFIG_PATH="$CONF_DIR/clawdbot.json"

  TOKEN=$(head -c 16 /dev/urandom | od -A n -t x1 | tr -d ' \n')
  PORT=18789

  cat > "$CLAWDBOT_CONFIG_PATH" <<EOF
  {
    "gateway": {
      "mode": "local",
      "bind": "lan",
      "port": $PORT,
      "auth": {
        "mode": "token",
        "token": "$TOKEN"
      },
      "controlUi": {
        "enabled": true,
        "allowInsecureAuth": true
      }
    }
  }
  EOF

  "$BIN" gateway run --allow-unconfigured --force --dev --bind lan --port "$PORT" --token "$TOKEN" &
  PID=$!
  echo "Gateway PID: $PID"
  echo "Endpoint: http://127.0.0.1:$PORT?token=$TOKEN"

  for i in $(seq 1 120); do
    if curl -so /dev/null --connect-timeout 1 "http://127.0.0.1:$PORT/" 2>/dev/null; then
      echo "Gateway is ready!"
      break
    fi
    sleep 2
  done

本方案沙箱基于 https://github.com/boxlite-ai/boxlite 一个轻松跑在本地,基于 micro-VM 的沙箱实现

2864 次点击
所在节点    OpenClaw
8 条回复
ccc00
1 月 31 日
请问可以运行在 vps 的 Linux 吗? 还是要运行在 kvm/qemu 的虚拟的 Linux ?
d0r1an
1 月 31 日
Linux: ls /dev/kvm 存在就行
macOS: M chips
Windows: WLS2
@ccc00
ccc00
1 月 31 日
@d0r1an 感谢回复
iSpy
2 月 1 日
~/code/clawBox via  v3.14.2 (.venv)
❯ python moltbox.py
Starting MoltBot in micro-VM sandbox...
Type 'exit' or press Ctrl+D to quit


Error: BoxOptions.__new__() got an unexpected keyword argument 'reuse_existing'
Traceback (most recent call last):
File "/Users/jon/code/clawBox/moltbox.py", line 12, in main
async with InteractiveBox(name="moltbox", image="ubuntu:26.04", env=[("TERM", term_mode)], ports=[(18789, 18789)], auto_remove=False, reuse_existing=True) as itbox:
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/jon/code/clawBox/.venv/lib/python3.14/site-packages/boxlite/interactivebox.py", line 73, in __init__
super().__init__(
~~~~~~~~~~~~~~~~^
image=image,
^^^^^^^^^^^^
...<5 lines>...
**kwargs,
^^^^^^^^^
)
^
File "/Users/jon/code/clawBox/.venv/lib/python3.14/site-packages/boxlite/simplebox.py", line 82, in __init__
self._box_options = BoxOptions(
~~~~~~~~~~^
image=image,
^^^^^^^^^^^^
...<3 lines>...
**kwargs,
^^^^^^^^^
)
^
TypeError: BoxOptions.__new__() got an unexpected keyword argument 'reuse_existing'

~/code/clawBox via  v3.14.2 (.venv)
❯ pip list
Package Version
------- -------
boxlite 0.5.8
pip 25.3
silence01
2 月 4 日
@iSpy 可以把那个参数去掉
d0r1an
2 月 4 日
@iSpy https://github.com/boxlite-ai/boxlite/releases/tag/v0.5.9

刚发了新版本,把 reuse_existing 带上了,麻烦再试试
iSpy
2 月 12 日
@d0r1an 👍,OK 啦
d0r1an
2 月 12 日
@iSpy 我还写了一个例子,可以直接拉起

https://www.v2ex.com/t/1191328

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1189650

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX