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

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

  •  
  •   d0r1an · 4 小时 26 分钟前 · 173 次点击
    #!/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 的沙箱实现

    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   967 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 19:10 · PVG 03:10 · LAX 11:10 · JFK 14:10
    ♥ Do have faith in what you're doing.