diff --git a/docs/agent-skills.md b/docs/agent-skills.md index 7b84b294..d8503308 100644 --- a/docs/agent-skills.md +++ b/docs/agent-skills.md @@ -194,8 +194,8 @@ Docker、CubeSandbox、E2B 均通过同一套空间配置 CRUD、连接检查和 - **单机部署**:不配置 `REDIS_ADDR`(或 Lite 模式)时使用进程内内存 binding,仅限单实例。进程重启会丢失 session→sandbox 映射,remote 侧沙箱成为孤儿(注意:**TTL 到期只会暂停、不会销毁**,见下)。绑定丢失后,**入站关闭(默认)的 Cube / E2B 配置不会再按 metadata 领养旧沙箱**——旧沙箱的 traffic token 随绑定一起没了且 provider 不会重发,领养只会得到一个每次数据面调用都 403 的死会话。lifecycle 会直接删掉它再新建,`/workspace` 里的临时文件随之丢失。Docker 没有 traffic token 概念,照旧领养。 - **切换 provider**:不同 provider 的 sandbox ID 不通用。智能体改选配置只影响之后新建的沙箱,已有沙箱继续按 session pin 回收。 - **⚠️ 孤儿沙箱不会被 TTL 自动回收**:会话沙箱创建时使用 `onTimeout=pause` + `autoResume=true`(见 `buildSessionCreateRequest`),因此 **TTL 到期是"暂停"而非"销毁"**——保留状态本就是 pause 的目的。加上 CAS 换绑会把旧 sandboxID 从 binding store 覆盖掉,被替换的沙箱会变成**无人知晓 ID 的 paused 孤儿**,持续占用快照存储与费用。删除会话(`session.go` 的 destroyer)与 lifecycle 的惰性 orphan cleanup 都覆盖不到这种情况。生产环境需依赖按 metadata 列举并与 binding 对账的清理任务来回收(`internal/sandbox/orphan_reaper.go`),且**必须显式包含 `paused` 状态**。对账维度是 `(tenant_id, config_id)` 而非仅 `tenant_id`:同一工作区的两份配置可能指向**同一个 provider 账号**(例如同一个 E2B Key 只差模板),只按 `tenant_id` 过滤会把另一份配置的沙箱一并误删。 -- **网络策略**:每份具名沙箱配置带一块 `network` 策略,作用于该配置下所有沙箱(会话、技能安装、深度检查共用同一份)。默认**出站放行、入站关闭**——入站关闭意味着沙箱公网 URL 必须携带创建时签发的 traffic token,WeKnora 自身的 envd 链路会自动携带(Cube 由 SDK 附加,E2B 由 WeKnora 的数据面 transport 附加)。若 Cube / E2B 在入站关闭时没有签发 token,create 会失败并销毁该沙箱,而不是把空凭证写入 binding(数据面 403 会被当成 authentication,会话会永久卡住)。管理员可配置 allow / deny 列表,Cube 额外支持 CubeEgress L7 规则(scheme / sni / host / method / path + 审计 + header 注入),E2B 额外支持按 host 注入 header。Docker 只能整体开关(`bridge` / `none`),表单不展示入站/出站 radio,避免切到 Cube/E2B 时把「公网可访问」带过去。**改策略只影响之后新建的沙箱**:本期不做运行中热更新。 -- **⚠️ 升级行为变更**:入站默认从「公网可达」改为「要求凭证」。如果某个部署依赖浏览器直连沙箱端口(而不是经 WeKnora 代理),需要在该沙箱配置的「网络策略 → 入站访问」里改成「公网可访问」。 +- **网络策略**:每份具名沙箱配置带一块 `network` 策略,作用于该配置下所有沙箱(会话、技能安装、深度检查共用同一份)。默认**出站放行、入站关闭**——入站关闭意味着沙箱公网 URL 必须携带创建时签发的 traffic token,WeKnora 自身的 envd 链路会自动携带(Cube 由 SDK 附加,E2B 由 WeKnora 的数据面 transport 附加)。若 Cube / E2B 在入站关闭时没有签发 token,create 会失败并销毁该沙箱,而不是把空凭证写入 binding(数据面 403 会被当成 authentication,会话会永久卡住)。管理员可配置 allow / deny 列表,Cube 额外支持 CubeEgress L7 规则(scheme / sni / host / method / path + 审计 + header 注入),E2B 额外支持按 host 注入 header。Docker 只能整体开关(`bridge` / `none`)。入站在表单里不可改,保存时一律写入「要求凭证」。**改策略只影响之后新建的沙箱**:本期不做运行中热更新。 +- **⚠️ 升级行为变更**:入站默认从「公网可达」改为「要求凭证」。浏览器或外部服务若要直连沙箱端口,不能再从管理界面打开入站。 ## Agent 工具 diff --git a/frontend/src/components/SandboxConfigEditorDrawer.network.test.mjs b/frontend/src/components/SandboxConfigEditorDrawer.network.test.mjs index 3350eb0d..f46d5f92 100644 --- a/frontend/src/components/SandboxConfigEditorDrawer.network.test.mjs +++ b/frontend/src/components/SandboxConfigEditorDrawer.network.test.mjs @@ -69,11 +69,25 @@ test('docker network mode moved into the network policy section', () => { ) }) -test('inbound defaults to credential-required and egress to allowed', () => { - assert.match( +test('inbound is always credential-required and never shown', () => { + assert.doesNotMatch( source, - /const allowPublicInbound = ref\(false\)/, - 'inbound closed is the default', + /settings\.sandbox\.inboundAccess/, + 'the inbound radio must not appear in the form', + ) + assert.doesNotMatch( + source, + /allowPublicInbound/, + 'the form must not keep a public-inbound control', + ) + const payloadBlock = source.slice( + source.indexOf('function collectNetworkPolicy'), + source.indexOf('function close'), + ) + assert.doesNotMatch( + payloadBlock, + /allow_public_inbound/, + 'saves must omit allow_public_inbound so the zero value (require credentials) is stored', ) assert.match( source, @@ -206,20 +220,15 @@ test('docker payload omits hidden allow and deny lists', () => { ) }) -test('docker hides inbound and egress radios that it cannot honour', () => { +test('docker hides egress radios that it cannot honour', () => { const networkBlock = source.slice( source.indexOf('settings.sandbox.sectionNetwork'), source.indexOf('settings.sandbox.sectionEnvironment'), ) assert.match( networkBlock, - /v-if="backend !== 'docker'"[\s\S]*settings\.sandbox\.inboundAccess[\s\S]*settings\.sandbox\.egressDefault/, - 'inbound and egress radios must not render for Docker', - ) - assert.match( - source, - /function selectBackend[\s\S]*crossingDocker[\s\S]*allowPublicInbound\.value = false/, - 'switching across Docker must not carry a public-inbound flag into Cube/E2B', + /v-if="backend !== 'docker'"[\s\S]*settings\.sandbox\.egressDefault/, + 'egress radios must not render for Docker', ) }) @@ -274,6 +283,35 @@ test('cube L7 rules collapse to a name bar', () => { false, 'E2B expanded body must not grow with a second delete control', ) + assert.match( + cubeRulesBlock, + /:key="rule\.key"/, + 'Cube rules must key on a stable id so reorder does not remount the open card', + ) + assert.match( + cubeRulesBlock, + /moveCubeRule\(index, -1\)/, + 'the name bar must offer move-up', + ) + assert.match( + cubeRulesBlock, + /moveCubeRule\(index, 1\)/, + 'the name bar must offer move-down', + ) + + const mover = source.match( + /function moveCubeRule\(index: number, delta: number\) \{\n([\s\S]*?)\n\}/, + ) + assert.ok(mover, 'moveCubeRule must exist') + const move = new Function('cubeRules', 'index', 'delta', `${mover[1]}`) + const rules = [{ key: 'a' }, { key: 'b' }, { key: 'c' }] + move({ value: rules }, 2, -1) + assert.deepEqual(rules.map((row) => row.key), ['a', 'c', 'b']) + move({ value: rules }, 0, -1) + assert.deepEqual(rules.map((row) => row.key), ['a', 'c', 'b'], 'the first row cannot move up') + move({ value: rules }, 2, 1) + assert.deepEqual(rules.map((row) => row.key), ['a', 'c', 'b'], 'the last row cannot move down') + assert.match( source, /for \(const rule of cubeRules\.value\) rule\.expanded = false/, diff --git a/frontend/src/components/SandboxConfigEditorDrawer.vue b/frontend/src/components/SandboxConfigEditorDrawer.vue index 945bc0e2..88d5c736 100644 --- a/frontend/src/components/SandboxConfigEditorDrawer.vue +++ b/frontend/src/components/SandboxConfigEditorDrawer.vue @@ -432,14 +432,6 @@