Skip to content

feat(sandbox): add sandbox module#465

Closed
miclle wants to merge 45 commits into
qiniu:masterfrom
miclle:sandbox
Closed

feat(sandbox): add sandbox module#465
miclle wants to merge 45 commits into
qiniu:masterfrom
miclle:sandbox

Conversation

@miclle

@miclle miclle commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

概述

  • 新增 Qiniu Sandbox Python SDK 模块,覆盖生命周期、命令执行、文件系统、Git、PTY、模板、资源挂载和注入规则等能力。
  • 在 Qiniu Sandbox API 支持的范围内,尽量对齐 E2B Python SDK 的常用方法名和函数签名。
  • 补充 sandbox 示例、基于 .env 的示例配置、单元测试和集成测试;集成测试与示例已覆盖远端 Git push 场景。

验证

  • /tmp/qiniu-python-sdk-test-venv/bin/python -m pytest tests/cases/test_services/test_sandbox -q -> 28 passed, 1 skipped
  • 已使用本地 .env 逐个运行所有 sandbox examples,均成功退出。
  • /tmp/qiniu-python-sdk-test-venv/bin/python -m flake8 --show-source --max-line-length=160 ./qiniu
  • python3 -m compileall -q qiniu tests examples
  • git diff --check

备注

  • docs/sandbox-e2b-python-sdk-differences.md 按要求未包含在本 PR 中。
  • 唯一 skipped 的 sandbox 测试是 PTY input;当前 envd 对该操作返回 501。

miclle added 4 commits June 23, 2026 16:05
Add an E2B-style sandbox client with lifecycle, envd commands, filesystem, git, template, resource, and injection-rule support.

Include .env-based examples plus unit and integration coverage for the new sandbox surface.
Add PTY, command streaming, filesystem watcher/write_files, Git helpers and credential authentication APIs for the sandbox module. Expand sandbox unit/integration tests, runnable examples, and the E2B Python SDK differences document including remote Git push coverage.
Keep the sandbox runtime, test, and example changes tracked while removing the generated E2B differences document from the submitted branch.
Return command handles from a streaming start path so background commands do not wait for process completion. Bound wait_for_ready health probes with per-request timeouts and cover both review fixes with tests.
@qiniu-prow qiniu-prow Bot added the size/XXL label Jun 23, 2026
@miclle miclle marked this pull request as ready for review June 23, 2026 11:18

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new sandbox service module under qiniu/services/sandbox to support sandbox management, command execution, filesystem operations, git helpers, and pty support, along with examples and tests. The review feedback highlights several critical issues and improvement opportunities, including potential unhandled StopIteration exceptions in commands.py and pty.py, overly broad exception handling across multiple files, inline imports violating PEP 8, missing explicit file encoding when opening files, and the use of generic RuntimeError instead of SandboxError.

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.

Comment thread qiniu/services/sandbox/commands.py Outdated
Comment thread qiniu/services/sandbox/pty.py Outdated
Comment thread qiniu/services/sandbox/pty.py Outdated
Comment thread qiniu/services/sandbox/sandbox.py Outdated
Comment thread examples/sandbox_runtime.py Outdated
Comment thread qiniu/services/sandbox/client.py Outdated
Comment thread qiniu/services/sandbox/commands.py Outdated
Comment thread qiniu/services/sandbox/config.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py Outdated
Comment thread qiniu/services/sandbox/sandbox.py Outdated

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review findings:

Comment thread qiniu/services/sandbox/sandbox.py Outdated
Comment thread qiniu/services/sandbox/sandbox.py
Comment thread qiniu/services/sandbox/sandbox.py
miclle added 3 commits June 23, 2026 19:44
Add E2B-style filesystem info objects, stream reads, IO writes, Git structured status and branches, Git typed exceptions, ReadyCmd helpers, is_running, and compatible Git config signatures. Keep Volume, Snapshot, and MCP gateway behavior out of scope.
Use temporary remote credential URLs for authenticated push and pull, restoring the original remote after success or failure.

Forward request_timeout/timeout through filesystem file transfers and cover the behavior with sandbox tests.
Handle empty envd streams, tighten sandbox exception handling, refresh traffic tokens, and prevent stale paginator tokens.

Add regression coverage for reviewer feedback and keep external Git TLS failures from failing integration runs.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new sandbox service (qiniu/services/sandbox) to the Qiniu Python SDK, adding support for sandbox lifecycle management, filesystem operations, command execution, git integration, and PTY terminals, along with examples and tests. Key feedback points out several robustness and compatibility issues: a potential crash in wait_for_ready when the timeout reaches zero, unhandled ValueError exceptions during UTF-8 decoding of base64 data, format string vulnerabilities in dangerously_authenticate when passwords contain %, missing URL-encoding for Git credentials, memory-inefficient streaming in filesystem reads, Python 2 compatibility issues when encoding unicode stdin data, and incorrect query parameter serialization for sandbox metrics.

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.

Comment thread qiniu/services/sandbox/sandbox.py
Comment thread qiniu/services/sandbox/commands.py
Comment thread qiniu/services/sandbox/git.py
Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py Outdated
Comment thread qiniu/services/sandbox/commands.py
Comment thread qiniu/services/sandbox/pty.py
Comment thread qiniu/services/sandbox/client.py Outdated

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review finding: one credential-handling bug found in the new sandbox Git helper. I did not find other issues worth raising in the reviewed diff.

Comment thread qiniu/services/sandbox/git.py Outdated
Encode Git credentials safely, handle wait/read/stdin edge cases, and serialize metrics IDs consistently.

Add regression tests for the second PR feedback round.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive sandbox service to the Qiniu Python SDK, including a client, sandbox instance management, filesystem utilities, Git operations, and PTY support, along with examples and tests. Key feedback from the review includes addressing a potential output distortion and crash in Base64 decoding, fixing credential leakage vulnerabilities in Git authentication and remote credential restoration, importing a missing error class, and establishing a default HTTP request timeout to prevent indefinite hangs.

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.

Comment thread qiniu/services/sandbox/commands.py
Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/git.py
Comment thread qiniu/services/sandbox/client.py Outdated

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review findings: I found two Python 2 compatibility regressions in the new sandbox module. The package still advertises Python 2.7 support, so these paths should use the existing compatibility helpers or otherwise handle unicode text explicitly.

Comment thread qiniu/services/sandbox/commands.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py Outdated
Avoid credential exposure in git authentication, report remote restore failures, use Python 2 compatible text handling, and set a default client timeout.

Cover the reviewer feedback with focused sandbox regression tests.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new sandbox service module to the Qiniu Python SDK, enabling users to manage sandboxes, interact with filesystems, execute commands, and perform Git operations within isolated environments. The changes include a client for the sandbox API, a command execution interface, filesystem management utilities, and integration tests. My review identified several areas for improvement: the is_running method in Sandbox needs robust error handling for network requests, the error handling logic in decode_connect_envelopes should be more explicit, the Filesystem.write method should leverage requests' native multipart support to avoid memory issues with large files, and the Git.add method requires input validation to handle single-string file paths correctly.

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.

Comment thread qiniu/services/sandbox/sandbox.py
Comment thread qiniu/services/sandbox/envd.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py Outdated
Comment thread qiniu/services/sandbox/git.py

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review findings:

I found two issues in the sandbox addition. One is a ready-command shell escaping problem, and the other is a lifecycle health-check edge case.

Comment thread qiniu/services/sandbox/template.py Outdated
Comment thread qiniu/services/sandbox/sandbox.py Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive sandbox service client and utilities to the Qiniu Python SDK, enabling sandbox creation, command execution, filesystem operations, Git integration, and PTY management, along with extensive tests and examples. The code review highlights three key areas for improvement: a potential timeout issue in wait_for_ready where the HTTP request timeout is overly restricted to the retry interval; a security vulnerability in dangerously_authenticate where sensitive Git credentials are written to /tmp with insecure default permissions; and a compatibility issue in the filesystem write method where passing absolute paths in multipart/form-data files could cause server-side errors.

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.

Comment thread qiniu/services/sandbox/sandbox.py Outdated
Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review finding: I found one remaining command-construction issue in the new sandbox Git helper.

Comment thread qiniu/services/sandbox/git.py

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive sandbox service client and SDK implementation under qiniu/services/sandbox, enabling sandbox creation, lifecycle management, command execution, filesystem operations, Git integration, and PTY interactions, along with extensive tests and examples. The review feedback highlights several critical improvement opportunities, including addressing a potential plain-text credential leak in the Git authentication helper, resolving Python 2 compatibility issues with file-like objects and unicode environment variables, and preventing connection leaks by ensuring streamed response connections are properly closed.

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.

Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/filesystem.py
Comment thread qiniu/services/sandbox/envd.py Outdated
Comment thread qiniu/services/sandbox/envd.py Outdated
Comment thread qiniu/services/sandbox/config.py

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review finding below.

Comment thread qiniu/services/sandbox/client.py Outdated

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No additional issues found in this review pass. The existing unresolved FennoAI thread on qiniu/services/sandbox/client.py remains the only finding I would keep open from the current diff.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new sandbox service module to the Qiniu Python SDK, complete with client APIs, sandbox lifecycle management, command execution, filesystem utilities, PTY support, Git helpers, example scripts, and extensive unit and integration tests. The review feedback highlights two improvement opportunities: refactoring a tuple-based lambda function in the Git example to improve readability, and correcting a minor indentation misalignment in the sandbox client options normalization to comply with PEP 8.

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.

Comment thread examples/sandbox_git.py Outdated
Comment thread qiniu/services/sandbox/client.py
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from gemini-code-assist Bot Jun 24, 2026
@qiniu qiniu deleted a comment from gemini-code-assist Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from gemini-code-assist Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@qiniu qiniu deleted a comment from fennoai Bot Jun 24, 2026
@miclle miclle closed this Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant