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

3 小时 25 分钟前
 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 的沙箱实现

157 次点击
所在节点    OpenClaw
0 条回复

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

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

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

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

© 2021 V2EX