/ examples / openclaw / README_zh.md
README_zh.md
 1  # OpenClaw Gateway 示例
 2  
 3  在 OpenSandbox 沙箱实例中启动 [OpenClaw](https://github.com/openclaw/openclaw) Gateway,并暴露 HTTP 访问端点。脚本会轮询 Gateway,直到返回 HTTP 200,然后打印可访问地址。
 4  
 5  ## 启动 OpenSandbox Server(本地)
 6  
 7  最新 OpenClaw 镜像可在这里查看:[OpenClaw Container Registry](https://github.com/openclaw/openclaw/pkgs/container/openclaw)。
 8  
 9  ### 注意事项(Docker 运行时要求)
10  
11  默认情况下,OpenSandbox Server 使用 `runtime.type = "docker"`,因此 **必须** 能访问可用的 Docker daemon。
12  
13  - **Docker Desktop**:确保已启动,然后执行 `docker version` 验证。
14  - **Colima(macOS)**:先启动 (`colima start`),再在启动 server 前导出 socket:
15  
16  ```shell
17  export DOCKER_HOST="unix://${HOME}/.colima/default/docker.sock"
18  ```
19  
20  预拉取 OpenClaw 镜像:
21  
22  ```shell
23  docker pull ghcr.io/openclaw/openclaw:latest
24  ```
25  
26  启动 OpenSandbox Server(日志会持续输出在当前终端):
27  
28  ```shell
29  uv pip install opensandbox-server
30  opensandbox-server init-config ~/.sandbox.toml --example docker
31  opensandbox-server
32  ```
33  
34  如果出现 `docker/transport/unixconn.py` 的 `FileNotFoundError: [Errno 2] No such file or directory`,通常表示 Docker unix socket 不存在或 Docker 未启动。
35  
36  ## 创建并访问 OpenClaw Sandbox
37  
38  该示例为快速体验预置了以下参数:
39  
40  - OpenSandbox Server:`http://localhost:8080`
41  - 镜像:`ghcr.io/openclaw/openclaw:latest`
42  - Gateway 端口:`18789`
43  - 超时时间:`3600s`
44  - Token:`OPENCLAW_GATEWAY_TOKEN`(默认:`dummy-token-for-sandbox`)
45  
46  在项目根目录安装依赖:
47  
48  ```shell
49  uv pip install opensandbox requests
50  ```
51  
52  运行示例(如需鉴权访问请设置真实 token):
53  
54  ```shell
55  export OPENCLAW_GATEWAY_TOKEN="$(openssl rand -hex 32)"
56  uv run python examples/openclaw/main.py
57  ```
58  
59  预期输出类似:
60  
61  ```text
62  Creating openclaw sandbox with image=ghcr.io/openclaw/openclaw:latest on OpenSandbox server http://localhost:8080...
63  [check] sandbox ready after 7.1s
64  Openclaw started finished. Please refer to 127.0.0.1:56123
65  ```
66  
67  最后打印的地址(如 `127.0.0.1:56123`)就是沙箱中 OpenClaw Gateway 的可访问端点。
68  
69  ## 参考
70  
71  - [OpenClaw](https://github.com/openclaw/openclaw)
72  - [OpenSandbox Python SDK](https://pypi.org/project/opensandbox/)