feat(sandbox): add sandbox module#451
Conversation
Add a Qiniu Sandbox module with E2B-compatible sandbox, filesystem, command, git, template, network, and typed-error surfaces. Include unit coverage plus gated real integration tests for sandbox lifecycle, files, commands, and git push flows.
Add reusable sandbox environment configuration and product examples covering lifecycle, envd, git, resources, request injection, metrics, and templates. Expand sandbox tests for typed resources, Kodo signing, integration flows, and safer temporary git credentials.
Add paginator, snapshot, MCP, PTY, and filesystem transfer helpers for sandbox runtime usage. Cover the new APIs with focused tests and runnable sandbox examples.
Add E2B-style sandbox runtime helpers, filesystem watching, Git option signatures, and expanded template builder APIs while preserving existing Qiniu call forms. Update type coverage and sandbox examples for the aligned APIs.
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive sandbox module to the Qiniu Node.js SDK, adding support for sandbox clients, filesystem operations, commands, git integration, PTY, templates, and volume management. It also includes extensive examples, type definitions, and integration tests. A critical issue was identified in the isBase64Text heuristic function within qiniu/sandbox/commands.js, which is prone to false positives for common plain text strings and can lead to incorrect decoding of standard gRPC-Web/Connect JSON transport fields; it is recommended to unconditionally decode these fields as base64 instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Encode Buffer stdin correctly, avoid newer Node-only URL and stream APIs in sandbox runtime paths, and quote Template shell helper arguments to preserve paths with spaces.
Return command handles as soon as process start events arrive, decode Connect JSON byte fields as base64, and cover live background command streams.
审查完成已提交非阻塞 PR review,包含 2 个内联问题:
验证:已运行 |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive Qiniu Sandbox module, including client APIs, commands, filesystem operations, git integration, PTY support, and template building, along with TypeScript definitions, examples, and integration tests. The review feedback highlights several critical improvements: resolving potential unhandled promise rejections in commands.js and pty.js when connections fail early, addressing a command injection vulnerability in git.js by validating the reset mode, enhancing the polling utility in util.js to tolerate transient network errors, and preventing path-length errors in template.js when parsing Dockerfile inputs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Add live command start timeout handling, prevent early wait promise rejection leaks, validate git reset modes, clean clone credentials for default destinations, retry transient poll errors, and avoid probing long Dockerfile text as a path.
审查完成已提交非阻塞 PR review,包含 1 个内联问题:
验证:已运行 |
There was a problem hiding this comment.
Code Review
This pull request introduces a new sandbox module to the Qiniu Node.js SDK, enabling integration with the Qiniu Sandbox OpenAPI. It includes a SandboxClient for managing sandboxes, templates, snapshots, and injection rules, alongside a Sandbox class for interacting with running instances via filesystem, command execution, PTY, and Git operations. TypeScript definitions, integration tests, and examples are also provided. The review feedback highlights several improvement opportunities: optimizing memory allocation in commands.js by avoiding repeated Buffer.concat calls, extending Git protocol support to http in git.js, fixing environment variable parsing for escaped quotes in template.js, and refactoring parseRequestUrl in util.js to use Node's native URL class.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Apply PTY start timeouts, optimize command JSON fallback buffering, support http git auth cleanup, parse escaped Dockerfile ENV values, and prefer native URL parsing with compatibility fallback.
审查完成已提交非阻塞 PR review,包含 2 个内联问题:
验证:已运行 |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive Qiniu Sandbox module to the Node.js SDK, adding client APIs, sandbox lifecycle management, filesystem operations, command execution, Git integration, and PTY support, along with integration tests and TypeScript definitions. The code review highlights several critical issues in the new implementation, including potential Node.js process crashes from unhandled JSON parsing exceptions on stream data, ignored custom timeout configurations in SandboxClient, incorrect parsing of multi-line Dockerfile instructions in template.js, and a lack of proper error propagation (such as throwing TemplateBuildError on build failures or TimeoutError on poll timeouts).
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
审查完成已提交非阻塞 PR review,包含 1 个内联问题:
验证:已运行 |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive Qiniu Sandbox module to the Node.js SDK, enabling developers to programmatically create and manage sandboxes, execute commands, interact with the filesystem, perform Git operations, and manage templates. Key feedback points include: supporting space-separated ENV syntax in Dockerfile parsing, properly passing the gzip option to rawRequest for automatic decompression in filesystem reads, avoiding credential exposure in Git clone URLs by using credential helpers, registering error listeners on response streams to prevent unhandled exceptions, caching the getMcpToken Promise to prevent concurrent duplicate API requests, and failing fast on fatal 4xx client errors during polling.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
审查完成已提交非阻塞 PR review,包含 1 个内联问题:
验证:已运行 |
There was a problem hiding this comment.
Code Review
This pull request introduces the Qiniu Sandbox feature to the Node.js SDK, providing comprehensive client implementations, TypeScript type definitions, integration tests, and practical examples. The review feedback identifies critical Denial of Service (DoS) vulnerabilities in commands.js, filesystem.js, and pty.js due to unbounded buffer accumulation during stream parsing. It also highlights several code quality and robustness issues, such as a bug in getSandboxesMetrics when handling single string IDs, fragile Dockerfile parsing for paths with spaces, missing err.resp checks in the filesystem exists method, and untrimmed trailing newlines in retrieved tokens.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive sandbox module to the Qiniu Node.js SDK, enabling developers to programmatically manage sandboxes, interact with filesystems, execute commands, manage Git repositories, and handle pseudo-terminals. It also includes TypeScript type definitions, extensive examples, and integration tests. The review feedback highlights three key areas for improvement: using printf instead of echo in the git credential helper to prevent backslash corruption, ensuring bunInstall respects user options when no packages are specified, and ensuring writeFiles consistently returns a rejected Promise instead of throwing synchronous errors during input validation.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive support for the Qiniu Sandbox feature, including client APIs, command execution, filesystem operations, git integration, PTY support, and template building, along with TypeScript definitions, examples, and integration tests. The review feedback highlights opportunities to prevent binary data corruption by normalizing Uint8Array and ArrayBuffer inputs to Node.js Buffers in the filesystem write methods, and suggests adding fail-fast validation for sandboxID in the getSandbox client method.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
审查完成已提交非阻塞 PR review。本轮未发现新的高置信问题;已重点检查最新 head 验证:已运行 |
There was a problem hiding this comment.
本轮评审未发现新的高置信问题。已重点检查最新 head 9e4fb25fef582db262dea1eb9ac4e24b1ae3a300 的 sandbox runtime、filesystem、PTY、Git、Template builder 和类型声明;已有 review/讨论中提出的问题没有重复展开。
验证说明:已运行 node --check 检查新增 sandbox 核心 JS 文件和 test/sandbox.test.js,并运行 git diff --check origin/master...HEAD,均通过。未能运行完整 mocha/类型检查:当前工作区没有 ./node_modules/.bin/mocha,npm run check-type 失败于 tsc: Permission denied。
审查完成已提交非阻塞 PR review,包含 1 个内联问题:
验证:已运行 |
审查完成已提交非阻塞 PR review。本轮未发现新的高置信问题;已重点检查当前 head 验证:已运行 未完成: |
There was a problem hiding this comment.
本轮评审未发现新的高置信问题。已重点检查当前 head e9ed56f72c61cf55e8be7dff40152a913fd99808 的 sandbox runtime、Connect 流式解析、filesystem/watchDir、Git 凭据处理、Template builder、导出入口和 TypeScript 声明;已有 review/讨论中指出的问题没有重复展开。
验证说明:已运行 git diff --check origin/master...HEAD、node --check qiniu/sandbox/*.js 和 node --check test/sandbox.test.js,均通过。未能运行完整类型检查/测试:npm run check-type 失败于 tsc: Permission denied,mocha 子集未运行,因为当前工作区没有 ./node_modules/.bin/mocha。
|
@fennoai review |
审查完成已提交非阻塞 PR review。本轮未发现新的高置信问题;已重点复核当前 head 验证:已运行 未能运行完整类型检查/测试: |
There was a problem hiding this comment.
本轮评审未发现新的高置信问题。已重点复核当前 head f48f9a6d6bfd235f0630fd592fcdc5a01543f4b9 相对上一轮已评审 head 的新增测试,以及 sandbox runtime、Connect 流式解析、filesystem/watchDir、Git 凭据处理、Template builder、客户端方法和类型声明的一致性;已有 review/讨论中指出的问题没有重复展开。
验证说明:已运行 git diff --check origin/master...HEAD、node --check qiniu/sandbox/*.js 和 node --check test/sandbox.test.js,均通过。未能运行完整类型检查/测试:npm run check-type 失败于 tsc: Permission denied,mocha 子集未运行,因为当前工作区没有 ./node_modules/.bin/mocha。
Run sandbox unit coverage before env-gated integration tests so PR coverage includes the sandbox modules even when Qiniu secrets are unavailable.
Remove the temporary ordering prefix now that sandbox coverage is run explicitly before env-gated tests.
Use the WHATWG URL helper when available and fall back to url.parse for Node 6 and 8 sandbox tests.
Run sandbox coverage with a sandbox-only include list and avoid wrapping env-gated tests in nyc when Qiniu secrets are unavailable.
Complete live command and PTY wait promises immediately when disconnecting so socket event timing cannot leave Node 14 tests hanging.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #451 +/- ##
==========================================
+ Coverage 86.14% 93.41% +7.27%
==========================================
Files 27 14 -13
Lines 2173 2006 -167
Branches 474 0 -474
==========================================
+ Hits 1872 1874 +2
+ Misses 301 132 -169
🚀 New features to boost your workflow:
|
变更内容
qiniu.sandbox模块,提供 Sandbox 产品的 Node.js SDK 封装,并在顶层导出Sandbox、SandboxClient、CommandExitError等常用入口。.env.example配置说明。测试与验证
npm run test:sandbox,CI 在无 Qiniu secrets 的 fork PR 中先运行 sandbox 单元覆盖,避免 env-gated 集成测试提前退出导致 coverage 失真。test/sandbox_integration.test.js与test/sandbox_types.ts,用于真实环境集成验证和类型验证。本地已验证:
npm run test:sandboxnpm run check-type./node_modules/.bin/eslint qiniu/sandbox/commands.js qiniu/sandbox/pty.js test/sandbox_*.test.js test/sandbox_helpers.jsgit diff --check备注
docs/sandbox-e2b-js-sdk-differences.md当前仍为本地未跟踪文件,未纳入本 PR。