WeKnora/docs/sandbox-cluster.md

131 lines
12 KiB
Markdown
Raw Normal View History

feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
# WeKnora 沙箱集群与标准模板
本文面向部署和平台管理员,说明如何把 CubeSandbox 或 E2B 接入 WeKnora。Docker、CubeSandbox、E2B 都在同一个空间设置页面通过同一套配置与检查接口管理;只有远端后端需要本文所述的集群和模板准备。普通智能体使用者不需要搭建模板,也不应该逐项猜测运行环境。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
## 谁负责什么
| 角色 | 职责 |
| --- | --- |
| WeKnora 发布流程 | 维护 `docker/Dockerfile.sandbox`,发布与 WeKnora 版本匹配的 `wechatopenai/weknora-sandbox` 镜像 |
| 集群管理员 | 部署 CubeSandbox 或开通 E2B,并保证控制面模板 API 可用 |
| 空间管理员 | 在“设置 → 沙箱后端”中填写集群地址和凭据,先完成连接验证,再选择接口返回的模板 |
| 智能体管理员 | 在智能体的 Skills 配置中选择已经验证过的沙箱后端 |
“WeKnora 标准模板”指模板内容由 WeKnora 维护,并不代表所有集群共享同一个模板 ID。CubeSandbox 的模板 ID、E2B 的模板 ID/别名都属于具体集群或账号;跨集群硬编码一个 ID 会指向不存在或内容不一致的模板。
## 标准模板包含什么
标准镜像定义在 `docker/Dockerfile.sandbox`,当前包含:
- Python 3.12;
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
- Node.js 20、npm 与 npx;
- jq 及基础 Shell 工具;
- `/workspace` 工作目录;
feat(sandbox): run sandboxed execs as root by default (#3067) * feat(sandbox): run sandboxed execs as root by default Every chat session owns its own sandbox, so the in-container account is not a tenant boundary and root is the least surprising default for an agent that installs packages and writes wherever it needs. Host and cross-tenant isolation stay at the container boundary. DefaultSandboxExecUser becomes "root" (remote_client.go) and the sandbox image ends with USER root. The three backends keep naming the account explicitly on every exec so the account a call lands on does not depend on which backend a workspace selected; the adapter default, the file operations and the artifact-directory bootstrap all follow the constant. The template still provisions a uid 1000 "user" account for interop with E2B/Cube tooling that addresses it by name. Root also makes the skill-install flow's account hand-over pointless, so it goes: verification no longer runs after a chown/chmod lock-down and a repair round no longer reopens the tree (normalizeSkillPermissions and reopenSkillDirForRepair are gone), and the prepare and scratch commands stop chowning. The scratch wipe now also clears /tmp, and the cache budget guard sizes only root's caches, since no second account can grow one. Verification is asserted to stay on the ordinary executor (no AsRoot, no AllowSkillsRoot) rather than on which account it ran as. * refactor(skills): install chat-time extras into the skill's own env PYTHONPATH / NODE_PATH pointed at a per-session overlay (/workspace/.skill-packages/<skill>) because the skill tree was frozen after install: root-owned, mode 555, and often built by `uv venv` with no pip, so `pip install --target` somewhere else was the only way a chat session could add a package. None of that holds now. The lock-down is gone and execs run as root, so a missing package goes straight into the skill's own environment, and the write is already session-local: a chat sandbox is built from the config's image and its filesystem dies with the session, so nothing reaches the image other sessions start from. The overlay bought nothing over that while splitting one skill's packages across two locations. SessionSkillPackageDir goes, and applySessionPackagePath becomes applySkillNodePath: it appends the skill's own node_modules after whatever the caller supplied, replacing a `+=` that prepended a bare separator once the overlay stopped seeding the variable. No PYTHONPATH is injected at all. Python dependencies are reached through the skill's venv interpreter, which the shell wrapper already puts first on PATH; the overlay-era value named the venv root, which is not an importable path. PYTHONPATH stays on the injected-name blacklist so a stored value cannot shadow the venv. The runtime hints and every prompt that described the overlay now name `<skillDir>/.venv/bin/python -m pip install` and `npm install` in the skill directory. frozenSkillTreeGuidance / isFrozenSkillVenvFailure are renamed for what they detect now that nothing is frozen. * docs(prompts): reserve /workspace/output for finished deliverables /workspace/output is the one directory an artifact collector reads, so everything written there is offered to the user as a deliverable. The prompts described it as the place for "deliverables" or "downloadable artifacts" without saying it is exclusively that, which reads as "the directory you write results to" — and a model doing multi-step work has results at every step. Drafts, intermediate renders and debug dumps land next to the finished file and the user is handed all of them. The four places that describe the workspace now say the same thing: the collector reads only /workspace/output, so finished deliverables go there and everything in progress goes anywhere else under /workspace. The attachment block gains the matching half for the other direction — /workspace/input holds the user's own files and is not ours to write to, which it previously implied by calling the paths "read-only inputs" while the tools that enforce it say so plainly. Only the /workspace/input half is enforced (write_sandbox_file refuses that tree). Whether a file is finished is a judgement no tool can make, so the output half stays guidance and is stated wherever the model is already reading about the workspace rather than in one place it might not see. * fix(skills): restore executable bundles and package recovery * style(sandbox): wrap prompt text for repository lint checks * fix(sandbox): guard recovery paths and document root execution --------- Co-authored-by: hailongzhao <hailongzhao@tencent.com> Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-07 05:03:35 +00:00
- UID 1000 的 `user` 账号(E2B 模板约定的账号名,保留供按名字寻址的工具与 `sudo` 使用;WeKnora 执行脚本与文件操作默认用的是 root,见 `DefaultSandboxExecUser`)。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
生产环境应使用与 WeKnora 相同的版本标签,不建议长期指向 `latest`。Skills 新增系统依赖时,应先更新标准镜像并重新注册模板,再切换集群的默认模板 ID。
### 镜像变体
`docker/Dockerfile.sandbox` 产出多个 target。CLI 变体内容相同、入口不同;桌面变体在同一套 Python 3.12 runtime 上再叠 XFCE,体积明显更大:
| 变体 | 标签 | 用途 |
| --- | --- | --- |
| `sandbox`(默认) | `wechatopenai/weknora-sandbox:<版本>` | Docker 后端的会话容器镜像;同时作为 E2B CLI 模板的基础镜像 |
| `cube` | `wechatopenai/weknora-sandbox:<版本>-cube` | CubeSandbox CLI 模板 |
| `desktop` | `wechatopenai/weknora-sandbox:<版本>-desktop` | E2B 图形桌面模板的基础镜像 |
| `desktop-cube` | `wechatopenai/weknora-sandbox:<版本>-desktop-cube` | CubeSandbox 图形桌面模板 |
区别在于 Cube 变体额外注入了 envd。Cube 直接把 OCI 镜像变成模板,并以 `GET :49983/health` 探活,这个端点只有 envd 提供;不带 envd 的镜像建模板必然以 `connection refused` 失败。E2B 不需要这个变体,因为它的构建流程会自行注入 envd;Docker 后端则完全不需要 envd,也**尚未**使用 `desktop` 变体。详见 [Cube 自带镜像接入](https://cubesandbox.com/zh/guide/tutorials/bring-your-own-image.html)。图形桌面的中继、票据与安全约束见 [沙箱图形桌面](./sandbox-desktop.md)。
feat(sandbox): run sandboxed execs as root by default (#3067) * feat(sandbox): run sandboxed execs as root by default Every chat session owns its own sandbox, so the in-container account is not a tenant boundary and root is the least surprising default for an agent that installs packages and writes wherever it needs. Host and cross-tenant isolation stay at the container boundary. DefaultSandboxExecUser becomes "root" (remote_client.go) and the sandbox image ends with USER root. The three backends keep naming the account explicitly on every exec so the account a call lands on does not depend on which backend a workspace selected; the adapter default, the file operations and the artifact-directory bootstrap all follow the constant. The template still provisions a uid 1000 "user" account for interop with E2B/Cube tooling that addresses it by name. Root also makes the skill-install flow's account hand-over pointless, so it goes: verification no longer runs after a chown/chmod lock-down and a repair round no longer reopens the tree (normalizeSkillPermissions and reopenSkillDirForRepair are gone), and the prepare and scratch commands stop chowning. The scratch wipe now also clears /tmp, and the cache budget guard sizes only root's caches, since no second account can grow one. Verification is asserted to stay on the ordinary executor (no AsRoot, no AllowSkillsRoot) rather than on which account it ran as. * refactor(skills): install chat-time extras into the skill's own env PYTHONPATH / NODE_PATH pointed at a per-session overlay (/workspace/.skill-packages/<skill>) because the skill tree was frozen after install: root-owned, mode 555, and often built by `uv venv` with no pip, so `pip install --target` somewhere else was the only way a chat session could add a package. None of that holds now. The lock-down is gone and execs run as root, so a missing package goes straight into the skill's own environment, and the write is already session-local: a chat sandbox is built from the config's image and its filesystem dies with the session, so nothing reaches the image other sessions start from. The overlay bought nothing over that while splitting one skill's packages across two locations. SessionSkillPackageDir goes, and applySessionPackagePath becomes applySkillNodePath: it appends the skill's own node_modules after whatever the caller supplied, replacing a `+=` that prepended a bare separator once the overlay stopped seeding the variable. No PYTHONPATH is injected at all. Python dependencies are reached through the skill's venv interpreter, which the shell wrapper already puts first on PATH; the overlay-era value named the venv root, which is not an importable path. PYTHONPATH stays on the injected-name blacklist so a stored value cannot shadow the venv. The runtime hints and every prompt that described the overlay now name `<skillDir>/.venv/bin/python -m pip install` and `npm install` in the skill directory. frozenSkillTreeGuidance / isFrozenSkillVenvFailure are renamed for what they detect now that nothing is frozen. * docs(prompts): reserve /workspace/output for finished deliverables /workspace/output is the one directory an artifact collector reads, so everything written there is offered to the user as a deliverable. The prompts described it as the place for "deliverables" or "downloadable artifacts" without saying it is exclusively that, which reads as "the directory you write results to" — and a model doing multi-step work has results at every step. Drafts, intermediate renders and debug dumps land next to the finished file and the user is handed all of them. The four places that describe the workspace now say the same thing: the collector reads only /workspace/output, so finished deliverables go there and everything in progress goes anywhere else under /workspace. The attachment block gains the matching half for the other direction — /workspace/input holds the user's own files and is not ours to write to, which it previously implied by calling the paths "read-only inputs" while the tools that enforce it say so plainly. Only the /workspace/input half is enforced (write_sandbox_file refuses that tree). Whether a file is finished is a judgement no tool can make, so the output half stays guidance and is stated wherever the model is already reading about the workspace rather than in one place it might not see. * fix(skills): restore executable bundles and package recovery * style(sandbox): wrap prompt text for repository lint checks * fix(sandbox): guard recovery paths and document root execution --------- Co-authored-by: hailongzhao <hailongzhao@tencent.com> Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-07 05:03:35 +00:00
Cube 变体只发布 linux/amd64——envd 的来源镜像 `cubesandbox-base` 没有 arm64,Cube 自身的 PVM 形态也只支持 x86_64。变体内 envd 以 root 运行,脚本按请求指定的账号执行;WeKnora 默认显式指定 root。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
## CubeSandbox
### 先选部署形态
| 形态 | 适用 | 硬性前提 |
| --- | --- | --- |
| 裸金属 / 物理机 | 已有可用 KVM 的机器 | `/dev/kvm` 可读写;root 权限 |
| PVM | 云厂商屏蔽了嵌套虚拟化、`/dev/kvm` 不可用 | 仅 x86_64;需安装 PVM 宿主机内核并重启;ARM64 不支持 |
| Kubernetes(preview) | 已有集群、要多节点 | K8s 1.24+;计算节点打标签;计算节点非裸金属时需开启 PVM bootstrap |
三种形态共同的前提:
- glibc ≥ 2.31(官方二进制基于 Ubuntu 20.04 构建);
- `/data/cubelet` 挂载 XFS,且开启 reflink(快照的 Copy-on-Write 依赖它)。Ubuntu/Debian 默认 ext4,需要单独准备分区或 loop 设备;
- 至少 50 GB 可用磁盘(要做多个模板则建议 200 GB 以上)、内存 ≥ 8 GB;
- 内核支持 eBPF 且 `/sys/fs/bpf` 已挂载为 bpffs(Cubelet 的网络运行时依赖);
- 具备 `resolvectl` 或 NetworkManager(安装脚本据此配置 `cube.app` 的 DNS 解析);
- Docker 可用(MySQL/Redis 以 Docker Compose 运行)。
安装脚本会把 CubeMaster、Cubelet、CubeShim 作为宿主机进程运行,因此**不能在没有 systemd 的容器化环境里部署**。CI 容器、无 init 系统的开发机请改用 K8s 形态或另找一台主机。
### 制作模板并对接 WeKnora
1. 按 [CubeSandbox Quick Start](https://github.com/TencentCloud/CubeSandbox/blob/master/docs/zh/guide/quickstart.md) 完成控制面、计算节点、CubeProxy 与域名解析。生产环境还需按官方文档完成鉴权、TLS、网络策略与多节点部署。
2. 在 WeKnora 的空间设置中填写 CubeAPI、CubeProxy、sandbox domain 和可选 API Key。需要自定义 guest DNS 时填写「DNS 服务器」(须为 IP);留空则使用集群默认。若这些端点位于 RFC1918/loopback 网络,显式打开“允许访问私网集群地址”。
3. 点击“连接并继续”。WeKnora 先验证控制面地址与凭据,通过后才进入模板步骤并列出集群模板。**不会自动创建桌面模板**。没有 WeKnora 标准(CLI)模板时在占位卡片上点「创建」,会从 `wechatopenai/weknora-sandbox:main-cube` 发起构建。需要图形桌面时再点桌面占位卡片上的「创建」(XFCE 镜像更重,E2B 为 4CPU/4GB,Cube 可写层 8G)。改 DNS 或需要换镜像时在对应卡片上点「重建」:优先对现有模板做 in-place rebuild(模板 ID 不变);只有 redo 被拒绝时才先建新模板、成功后再删旧的。已安装 Skill 的配置(以及同一集群上其它已装 Skill 的配置)不能重建,也不能在 CLI / 桌面之间切换。失败模板同样用「重建」(CubeMaster 拒绝 redo、错误码 130400 时尤其需要)。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
4. 模板构建状态会自动刷新。状态变为 `READY` 后才可选择并进入运行配置;界面显示模板名称、状态和版本,配置内部才保存该集群自己的 `template_id`。
feat(sandbox): run sandboxed execs as root by default (#3067) * feat(sandbox): run sandboxed execs as root by default Every chat session owns its own sandbox, so the in-container account is not a tenant boundary and root is the least surprising default for an agent that installs packages and writes wherever it needs. Host and cross-tenant isolation stay at the container boundary. DefaultSandboxExecUser becomes "root" (remote_client.go) and the sandbox image ends with USER root. The three backends keep naming the account explicitly on every exec so the account a call lands on does not depend on which backend a workspace selected; the adapter default, the file operations and the artifact-directory bootstrap all follow the constant. The template still provisions a uid 1000 "user" account for interop with E2B/Cube tooling that addresses it by name. Root also makes the skill-install flow's account hand-over pointless, so it goes: verification no longer runs after a chown/chmod lock-down and a repair round no longer reopens the tree (normalizeSkillPermissions and reopenSkillDirForRepair are gone), and the prepare and scratch commands stop chowning. The scratch wipe now also clears /tmp, and the cache budget guard sizes only root's caches, since no second account can grow one. Verification is asserted to stay on the ordinary executor (no AsRoot, no AllowSkillsRoot) rather than on which account it ran as. * refactor(skills): install chat-time extras into the skill's own env PYTHONPATH / NODE_PATH pointed at a per-session overlay (/workspace/.skill-packages/<skill>) because the skill tree was frozen after install: root-owned, mode 555, and often built by `uv venv` with no pip, so `pip install --target` somewhere else was the only way a chat session could add a package. None of that holds now. The lock-down is gone and execs run as root, so a missing package goes straight into the skill's own environment, and the write is already session-local: a chat sandbox is built from the config's image and its filesystem dies with the session, so nothing reaches the image other sessions start from. The overlay bought nothing over that while splitting one skill's packages across two locations. SessionSkillPackageDir goes, and applySessionPackagePath becomes applySkillNodePath: it appends the skill's own node_modules after whatever the caller supplied, replacing a `+=` that prepended a bare separator once the overlay stopped seeding the variable. No PYTHONPATH is injected at all. Python dependencies are reached through the skill's venv interpreter, which the shell wrapper already puts first on PATH; the overlay-era value named the venv root, which is not an importable path. PYTHONPATH stays on the injected-name blacklist so a stored value cannot shadow the venv. The runtime hints and every prompt that described the overlay now name `<skillDir>/.venv/bin/python -m pip install` and `npm install` in the skill directory. frozenSkillTreeGuidance / isFrozenSkillVenvFailure are renamed for what they detect now that nothing is frozen. * docs(prompts): reserve /workspace/output for finished deliverables /workspace/output is the one directory an artifact collector reads, so everything written there is offered to the user as a deliverable. The prompts described it as the place for "deliverables" or "downloadable artifacts" without saying it is exclusively that, which reads as "the directory you write results to" — and a model doing multi-step work has results at every step. Drafts, intermediate renders and debug dumps land next to the finished file and the user is handed all of them. The four places that describe the workspace now say the same thing: the collector reads only /workspace/output, so finished deliverables go there and everything in progress goes anywhere else under /workspace. The attachment block gains the matching half for the other direction — /workspace/input holds the user's own files and is not ours to write to, which it previously implied by calling the paths "read-only inputs" while the tools that enforce it say so plainly. Only the /workspace/input half is enforced (write_sandbox_file refuses that tree). Whether a file is finished is a judgement no tool can make, so the output half stays guidance and is stated wherever the model is already reading about the workspace rather than in one place it might not see. * fix(skills): restore executable bundles and package recovery * style(sandbox): wrap prompt text for repository lint checks * fix(sandbox): guard recovery paths and document root execution --------- Co-authored-by: hailongzhao <hailongzhao@tencent.com> Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-09-07 05:03:35 +00:00
标准模板保留 uid 1000 的 `user` 兼容账号;WeKnora 默认显式以 root 执行脚本与文件操作。模板应提供可写的 `/workspace`,运行前会准备 `input`、`output` 和本次工作目录。技能安装的维护调用只准备其工作目录。自定义只读挂载仍限制 root 的写入。
多实例 WeKnora 必须配置 Redis,以共享 session 到 sandbox 的绑定,以及桌面中继的「上次 sandbox ID」(技能安装重建后跨副本仍能发出 `SANDBOX_REBUILT`)。只有单实例开发环境才应使用内存绑定。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
### 验证
界面上的“连接验证”只覆盖控制面,“完整验证”会真实创建、执行并销毁一个沙箱。要覆盖 WeKnora 实际依赖的全部语义(会话内状态保持、shell_exec 复用同一沙箱、附件暂存、产物收集、执行超时),在能访问集群的机器上跑一致性测试:
```bash
CUBE_API_URL=http://127.0.0.1:33000 \
CUBE_PROXY_URL=http://127.0.0.1:80 \
CUBE_TEMPLATE_ID=<模板 ID> \
go test -tags=integration ./internal/sandbox -run Integration -count=1 -v
```
测试结束会归还自己创建的沙箱;跑完用 `cubemastercli` 确认没有残留实例。
### 排障
| 现象 | 排查方向 |
| --- | --- |
| 连接验证失败 | CubeAPI 地址是否是控制面端口(不是 Dashboard 端口);私网地址是否已打开“允许访问私网集群地址” |
| 连接通过但执行报数据面错误 | CubeProxy 地址与 sandbox domain 是否与集群 `CUBE_API_SANDBOX_DOMAIN` 一致;Proxy 是否对 WeKnora 可达 |
| 模板长期停在构建中 | 镜像体积与网络;用 `cubemastercli tpl watch --job-id <id>` 看真实进度 |
| 模板构建失败 | 卡片上会显示集群返回的失败原因。未安装 Skill 时可点「重建」删掉失败模板并用当前配置新建;仅刷新列表不会再自动重建。已安装 Skill 的配置会拒绝重建,请新建沙箱 |
| 失败原因含 `TOOMANYREQUESTS` / Docker Hub 限流 | Cube 节点匿名拉 `wechatopenai/weknora-sandbox` 触发了 Hub 限额。等限额恢复后再刷新,或在节点上 `docker login` 后重试 |
| 失败原因是 `Get "http://<IP>:49983/health": connect: connection refused` | 模板镜像里没有 envd。确认建模板用的是 `-cube` 变体镜像;若已是该变体,再查 Cube 沙箱网段(默认 `192.168.0.0/18`)是否与物理内网冲突 |
| 沙箱能执行但「出网可用」失败 | 先看模板「公网访问」是否开启;WeKnora 标准模板构建会带 `allowInternetAccess`。guest DNS 来自标准模板构建时写入的 `dns`(设置页「DNS 服务器」/`dns_servers`)。留空时 Cubelet 会落到 `119.29.29.29`;私网或云上 UDP 53 到不了公网 DNS 时,填 Cube 宿主机 `/etc/resolv.conf` 里能用的地址,并避开 CubeVS 默认拒绝的 `10/8`、`172.16/12`、`192.168/16`。未安装 Skill 时,已有标准模板改 DNS 后在 weknora 卡片上点「重建」;已装 Skill 的配置请新建沙箱。其次 Cube 把沙箱 80/443 TPROXY 到 `192.168.0.1:8080/8443`,宿主机占用 `0.0.0.0:8080` 时 cube-egress 起不来。探测目标 `1.1.1.1` 在腾讯云也经常不通,国内目标可达即可 |
| 会话重连后状态丢失 | 多副本部署是否配置了 Redis 绑定存储;沙箱是否已被空闲 TTL 回收 |
### 已知限制
- K8s 部署仍是 preview:计算节点资源紧张时 Pod 可能被误驱逐,计算面升级会重建 Big Pod 并中断存量沙箱。
- 官方镜像的 Multi-Arch 覆盖尚不完整,ARM64 环境需自行构建模板镜像。
- 暂不支持 GPU 直通。
其它 E2B 兼容后端(含容器隔离的 Kubernetes 实现)与协议层的统一方案见 [沙箱协议接入说明](./sandbox-protocol.md)。
## E2B 及其它 E2B 兼容实现
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
E2B 官方托管服务、自建 E2B Infrastructure,以及任意实现 E2B 协议的控制面(例如 Kubernetes 上以容器隔离的 Agent-Sandbox)都通过同一个 E2B 配置接入;自建集群通常还要填写 `proxy_url` 数据面网关,详见 [沙箱协议接入说明](./sandbox-protocol.md)。填写 API Key 后先执行“连接并继续”,流程与 Cube 相同:验证连接后列出账号可见模板;缺少 `weknora` 时点「创建 WeKnora 标准模板」,通过 E2B Template API 从标准镜像启动后台构建。自建部署还需填写 API URL 和 sandbox domain;E2B 上游通过 Terraform 提供 AWS、GCP 等部署方式,具体以 [E2B self-hosting guide](https://github.com/e2b-dev/infra/blob/main/self-host.md) 和 [E2B Template 文档](https://e2b.dev/docs/template/quickstart) 为准。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
## 在设置页面完成接入
1. 打开“设置 → 沙箱后端”,点击“添加沙箱后端”。
2. 填写该集群自己的 API、Proxy、sandbox domain 和凭据;这些值只保存在当前空间配置中,不读取 Sandbox 环境变量。
3. 点击“连接并继续”,验证控制面地址和凭据;连接通过后才加载模板列表。
4. 没有标准模板时点占位卡片上的「创建」,或选择集群已有的兼容模板;需要图形界面时再单独创建桌面模板。改 DNS / 镜像后在对应卡片上点「重建」。**该配置已安装 Skill 时不能更换或重建模板,也不能把 CLI 底模改成桌面(或反过来)**——技能环境绑在快照上,新底模不会进去;请新建一份沙箱再装 Skill。构建中的模板不可选择,状态会自动刷新。
feat(sandbox): 沙箱后端改为按空间配置,并补齐 E2B 模板与检测诊断 沙箱的后端类型、凭据、模板、超时和私网访问策略此前分散在部署级 WEKNORA_SANDBOX_* 环境变量里,一个实例只能有一套,租户之间无法各用 自己的 E2B 账号或自建 Cube 集群。现在这些配置全部落到空间维度的具名 沙箱配置上:部署环境不再提供覆盖项,未选择配置的智能体直接不启用脚本 执行,而不是静默回落到某个部署默认值——后者会让「这个智能体到底跑在 哪」无从判断。 同时把连接检测从「能不能连上控制面」扩展成可解释的诊断: - E2B 标准模板显式带上 default 标签构建。创建沙箱时裸模板名/ID 只解析 default 标签,构建带了别的标签就永远拿不到,表现为一个与「模板不存在」 无法区分的 404。 - 模板状态不再从历史构建或 spawn 次数反推就绪,只认当前构建;构建完成 却没有 default 标签的模板单独报成 untagged,因为它在列表里和「仍在构建」 长得一样,但等待永远不会有结果。 - 创建失败带上 HTTP 状态,404 走模板解释路径,给出具体到「重建模板」还是 「Key 属于其他团队」的结论。 - 探针脚本改在进程工作目录下暂存。系统临时目录在 macOS 上位于 /var/folders,Docker 虚拟机并不共享,挂载进容器后是空目录,真实技能执行 (脚本在 skills/ 下)却不会踩到,检测因此报假失败。 - 检测失败不再只说「命令输出与预期不符」,带上退出码与 stderr 首行。 前端把沙箱设置页与配置抽屉重做:凭据按「是否已配置」展示而非回显掩码, 删除与停用改为就地确认,占用情况走右侧抽屉,列表卡片展示模板状态、凭据、 超时等可判断健康度的事实。
2026-08-11 07:31:58 +00:00
5. 配置运行参数;上线前可执行一次“完整验证”。完整验证会真实创建、执行并销毁一个沙箱。
6. 保存后,在智能体 Skills 配置中选择该后端。对配置的修改只影响之后新建的沙箱;已有会话仍固定使用创建时的配置。
## 上线检查
- 模板版本与 WeKnora 版本匹配,且不依赖浮动的 `latest`;
- WeKnora 到控制面、Proxy 和 sandbox domain 的 DNS、TLS 与防火墙均已打通;
- 多实例部署已配置 Redis;
- API Key 只通过密钥管理或加密配置保存;
- “连接验证”和“完整验证”均通过;
- 已配置运行中与 paused 沙箱的容量监控、费用监控和孤儿清理;
- 切换模板或集群前已确认旧会话和旧沙箱的回收策略。