Skip to content

feat(sandbox): add sandbox module#466

Merged
miclle merged 46 commits into
qiniu:masterfrom
miclle:sandbox-clean
Jun 26, 2026
Merged

feat(sandbox): add sandbox module#466
miclle merged 46 commits into
qiniu:masterfrom
miclle:sandbox-clean

Conversation

@miclle

@miclle miclle commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

概述

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

验证

  • python3 -m flake8 examples/sandbox_*.py qiniu/services/sandbox tests/cases/test_services/test_sandbox --max-line-length=160
  • python3 -m compileall -q examples/sandbox_*.py qiniu/services/sandbox tests/cases/test_services/test_sandbox
  • env QINIU_SANDBOX_API_KEY= QINIU_API_KEY= E2B_API_KEY= QINIU_SANDBOX_ACCESS_KEY= QINIU_SANDBOX_SECRET_KEY= GIT_REPO_URL= GIT_USERNAME= GIT_PASSWORD= GITHUB_TOKEN= python3 -m pytest tests/cases/test_services/test_sandbox/test_client.py tests/cases/test_services/test_sandbox/test_config.py tests/cases/test_services/test_sandbox/test_envd.py tests/cases/test_services/test_sandbox/test_example_config.py -q -> 110 passed
  • GitHub Actions run 28086731528 已全部通过。

miclle added 30 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.
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.
Encode Git credentials safely, handle wait/read/stdin edge cases, and serialize metrics IDs consistently.

Add regression tests for the second PR feedback round.
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.
@qiniu-prow qiniu-prow Bot added the size/XXL label Jun 24, 2026

@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 integration to the Qiniu Python SDK, including modules for client API requests, command execution, filesystem operations, Git integration, PTY allocation, resource mounting, and template builds, along with extensive examples and tests. The review feedback highlights several critical issues: the lifecycle parameter is parsed but omitted from the sandbox creation request body, and allow_internet_access should use camelCase to match other API fields. Additionally, Python 2 compatibility issues in _decode_bytes could trigger UnicodeDecodeError, and unhandled exceptions in base64.b64decode might cause crashes. Finally, there are security concerns regarding the cleanup of temporary Git credentials for background commands if wait() is not called, and a parsing edge case in _is_legacy_config_call when repository paths contain dots.

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/client.py
Comment thread qiniu/services/sandbox/client.py Outdated
Comment thread qiniu/services/sandbox/commands.py Outdated
Comment thread qiniu/services/sandbox/commands.py Outdated
Comment thread qiniu/services/sandbox/git.py Outdated
Comment thread qiniu/services/sandbox/git.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:

  • One sandbox control-plane helper path is missing the same required-ID guard used by the neighboring lifecycle methods.

Comment thread qiniu/services/sandbox/client.py
@miclle miclle merged commit e6c3539 into qiniu:master Jun 26, 2026
10 checks passed
miclle added a commit that referenced this pull request Jun 26, 2026
Add the Qiniu Sandbox Python SDK surface from PR #466 as a single mainline commit.
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.

2 participants