Open
Conversation
- add sandbox type, image, and resource limit settings to values.yaml - inject sandbox env vars into app deployment - add K8s RBAC (ServiceAccount, Role, RoleBinding) for sandbox Jobs - add NetworkPolicy and ResourceQuota for sandbox namespace isolation - support existingSecret for OpenSandbox API key (recommended for production) - add opensandbox env vars to docker-compose.yml
- add lightweight K8s REST client (stdlib only) with SA token rotation and cache - add OpenSandbox REST client aligned with alibaba/OpenSandbox API spec - streaming JSONL command response parsing - endpoint discovery for execd access - multipart metadata file upload format - execd readiness polling via /ping - bound all io.ReadAll calls with LimitReader to prevent OOM - URL-encode all K8s API query parameters - validate sandbox ID format to prevent path traversal - strip null bytes in shellQuote to prevent shell truncation
- implement OpenSandbox backend using alibaba/OpenSandbox API - create sandbox → discover execd endpoint → wait ready → upload → execute → cleanup - support stdin via .stdin file upload + shell pipe - shell-quote all command arguments to prevent injection - verified end-to-end against real OpenSandbox server
…anager - implement KubernetesSandbox using K8s Job API with orphan GC - support stdin via ConfigMap .stdin file + sh -c pipe (exec-form when no stdin) - support args pass-through in both exec-form and shell-form - use namespace-scoped configmap list for access check - use sync.Once for Cleanup() to prevent double-close panic - wire ServiceAccountName from config into Job spec - wire both modes into sandbox manager with priority-based selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
描述 (Description)
为 sandbox 模块新增 kubernetes 和 opensandbox 两种执行模式,使部署在 K8s 集群中的用户无需依赖 Docker daemon,可直接使用原生 K8s Job 作为脚本沙箱运行环境;同时支持对接外部 alibaba/OpenSandbox 服务。
核心变更:
实现轻量级 K8s REST API 客户端(仅依赖 stdlib,无需 client-go)
实现 KubernetesSandbox:通过 ConfigMap 传递脚本、K8s Job 执行、Pod 日志采集
实现 OpenSandboxSandbox:对接 alibaba/OpenSandbox API,支持 execd 端点发现、流式响应解析、readiness polling
提供完整的 Helm 配置:RBAC、NetworkPolicy、ResourceQuota
新增 docker-compose.yml 环境变量支持
安全:Pod SecurityContext、drop ALL capabilities、只读根文件系统、seccomp、io.ReadAll 限制、URL 编码、sandbox ID 校验、shell 参数转义(含 null byte 过滤)
变更类型 (Type of Change)
影响范围 (Scope)
测试 (Testing)
测试步骤 (Test Steps)
检查清单 (Checklist)
相关 Issue
Fixes #840
截图/录屏 (Screenshots/Recordings)
opensandbox 验证

数据库迁移 (Database Migration)
配置变更 (Configuration Changes)
新增环境变量:
Helm values 新增 app.sandbox.kubernetes.* 和 app.sandbox.opensandbox.* 配置段,其中 API Key 支持通过 existingSecret 从 K8s Secret 注入。
docker-compose.yml 新增以上环境变量的传递(含 SSRF_WHITELIST)
部署说明 (Deployment Notes)
Kubernetes 模式
适用场景: 在 K8s 集群中部署 WeKnora,需要容器级隔离但集群中没有 Docker daemon(如使用 containerd/CRI-O 运行时)。
前置条件:
Helm 部署(推荐):
Helm 会自动创建以下资源:
Namespace:sandbox 专用命名空间
ServiceAccount:weknora-sandbox-runner(sandbox Pod 使用,禁用 token 自动挂载)
Role + RoleBinding:赋予 WeKnora 的 SA 在 sandbox 命名空间操作 jobs/configmaps/pods 的权限
NetworkPolicy:deny-all,sandbox Pod 无法访问任何网络
ResourceQuota:限制命名空间内资源总量
环境变量部署(非 Helm):
注意: 非 Helm 部署需手动创建 Namespace、ServiceAccount、RBAC、NetworkPolicy、ResourceQuota。可参考 helm/templates/sandbox-rbac.yaml 和 helm/templates/sandbox-resources.yaml。
Fallback 机制: 如果启动时检测到 K8s API 不可用(如不在集群内运行、SA token 缺失、命名空间无权限),会自动 fallback 到 local 模式并输出 warn 日志。
K8s 模式尚未在真实集群做端到端验证,建议合并前或合并后在测试集群验证完整流程(创建 ConfigMap → 创建 Job → 轮询状态 → 读日志 → 清理)
OpenSandbox 模式:
适用场景: 希望将沙箱执行环境完全隔离到独立的服务中,或在无 K8s 环境下需要容器级隔离。
前置条件:
OpenSandbox API 对接:
本实现对接以下 API(已通过真实服务验证):
Helm 部署(推荐):
环境变量部署(非 Helm):
Fallback 机制: 如果启动时 OpenSandbox health check 失败,会自动 fallback 到 local 模式。
网络配置注意事项:
容器化部署:如 WeKnora 与 OpenSandbox 在不同网络中(如 Docker Compose),需在 OpenSandbox 配置 [server] 段设置 eip 为 WeKnora 可达的主机名,并将该地址加入 SSRF_WHITELIST 环境变量。
execd 访问模式说明:
其他信息 (Additional Information)
安全措施: