V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
d0r1an
V2EX  ›  OpenClaw

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

  •  
  •   d0r1an · 1 月 30 日 · 622 次点击
    #!/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())
    
    • 执行 pip install boxlite

    • 执行 python moltbox.py 进入沙箱

    • 进入沙箱后,粘贴以下命令,按回车

      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
    
    • enjoy!

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

    4 条回复    2026-02-01 23:33:25 +08:00
    ccc00
        1
    ccc00  
       1 月 31 日
    请问可以运行在 vps 的 Linux 吗? 还是要运行在 kvm/qemu 的虚拟的 Linux ?
    d0r1an
        2
    d0r1an  
    OP
       1 月 31 日
    Linux: ls /dev/kvm 存在就行
    macOS: M chips
    Windows: WLS2
    @ccc00
    ccc00
        3
    ccc00  
       1 月 31 日   ❤️ 1
    @d0r1an 感谢回复
    iSpy
        4
    iSpy  
       8 小时 32 分钟前
    ~/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
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1618 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 00:05 · PVG 08:05 · LAX 16:05 · JFK 19:05
    ♥ Do have faith in what you're doing.