Repository navigation
feat: add Tenki sandbox provider - #17305
Conversation
Add a Tenki provider to the agent code-execution sandbox, alongside the existing local, self_managed, ssh, aliyun_codeinterpreter, and e2b providers. Each execution runs in a disposable Tenki microVM: the provider creates a session, runs the wrapped script over the SDK's exec, collects the structured result and artifacts, and terminates the session. - agent/sandbox/providers/tenki.py: TenkiProvider implementing SandboxProvider, using only the SDK's create/exec/destroy path (no volumes or snapshots). - Register the provider in the providers package, the client factory, and the admin Sandbox Settings (registry + config schema). - web: add the provider icon in admin sandbox settings. - test: unit tests covering execution, structured result, artifacts, non-zero exit, timeout, quota errors, idempotent destroy, and config schema.
Add unit tests for the auth-failure path (initialize maps UnauthorizedError to SandboxProviderConfigError) and for concurrent instances being independent (distinct sessions; destroying one leaves the other running).
Add Tenki to the provider lists in the sandbox quickstart and a short section covering its configuration (api_key, project_id, optional image/resources), supported languages, artifact handling, and that it is cloud-hosted with no local sandbox services required.
- Reject symlink artifacts via stat mode bits: fs.list does not populate is_symlink, so the previous check was dead; add a directory recursion depth cap to bound untrusted nested trees. - Make outbound network access configurable (allow_outbound, default true) instead of hardcoded, and expose it in the config schema. - Map SessionTerminated/SessionNotFound during exec to RuntimeError per the base contract instead of leaking SDK exception types. - Clarify that tenki-sandbox is an optional dependency (its protobuf requirement differs from RAGFlow's gRPC stack); document installing it. - Add tests for the JavaScript path, symlink rejection, output-size limit, disallowed artifact extension, and configurable outbound network.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR adds Tenki as a disposable microVM sandbox provider across Go and Python implementations, including lifecycle management, code execution, artifact handling, configuration, admin integration, documentation, UI metadata, dependencies, and tests. ChangesTenki Provider Support
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant AdminUI as Admin UI
participant SandboxMgr
participant TenkiProvider
participant TenkiSDK
AdminUI->>SandboxMgr: Configure Tenki provider
SandboxMgr->>TenkiProvider: Validate and initialize
TenkiProvider->>TenkiSDK: Create client and check connectivity
TenkiSDK-->>TenkiProvider: Connectivity result
AdminUI->>SandboxMgr: Test connection
SandboxMgr->>TenkiProvider: Create and execute sandbox
TenkiProvider->>TenkiSDK: Create session and execute wrapper
TenkiSDK-->>TenkiProvider: Execution result
TenkiProvider-->>SandboxMgr: Return test result
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
test/unit_test/agent/sandbox/test_tenki_provider.py (1)
192-214: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd tests for session-terminated/session-not-found mapping and remaining limit paths.
SessionTerminatedError/SessionNotFoundError→RuntimeErrormapping (tenki.pylines 211-214) has no dedicated test, despite being called out in the PR as covered ("session error mapping"). Similarly,max_artifacts,max_artifact_bytes, andMAX_ARTIFACT_DEPTHenforcement, andRateLimitedErrormapping increate_instance, aren't exercised here even though "directory-depth restrictions" and "size ... limits" are listed as tested in the PR summary.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit_test/agent/sandbox/test_tenki_provider.py` around lines 192 - 214, Add focused tests alongside test_tenki_provider_propagates_timeout and test_tenki_provider_create_maps_quota_error covering SessionTerminatedError and SessionNotFoundError mapping to RuntimeError, RateLimitedError mapping in create_instance, and enforcement of max_artifacts, max_artifact_bytes, and MAX_ARTIFACT_DEPTH. Reuse _FakeSandbox, _build_provider, and the existing provider APIs, asserting the documented exception types and messages for each path.agent/sandbox/providers/tenki.py (1)
490-494: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse
contextlib.suppressper Ruff SIM105.Based on static analysis: Ruff SIM105 "Use `contextlib.suppress(Exception)` instead of `try`-`except`-`pass`".♻️ Proposed refactor
+import contextlib + def _safe_terminate(self, sandbox) -> None: - try: - sandbox.terminate() - except Exception: - pass + with contextlib.suppress(Exception): + sandbox.terminate()🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@agent/sandbox/providers/tenki.py` around lines 490 - 494, Update _safe_terminate to use contextlib.suppress(Exception) around sandbox.terminate(), replacing the try/except/pass pattern while preserving the current behavior of ignoring termination exceptions.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@agent/sandbox/providers/tenki.py`:
- Around line 87-120: Add structured logging throughout the Tenki provider
lifecycle methods initialize, create_instance, execute_code, and
destroy_instance, including startup/connectivity, instance creation and
destruction, execution success, timeouts, and error-mapping branches for quota,
authentication, and terminated sessions. Use the project’s existing logger
conventions, include useful sanitized context such as operation,
instance/session identifiers, and outcomes, and never log api_key, project_id,
raw code, or stdout content.
- Around line 144-151: Update create_instance’s Tenki client call and
execute_code’s execution call to catch any remaining tenki_sandbox SDK exception
after their specific handlers, then wrap it in RuntimeError while preserving the
original exception as the cause. Keep the existing specialized mappings for
quota, rate-limit, authentication, timeout, and session-terminated errors
unchanged so both methods satisfy the base-class RuntimeError contract.
- Line 145: Update the Tenki call sites in initialize/create_instance, including
who_am_i() and self._client.create(**create_kwargs), to enforce an explicit HTTP
request timeout when callers do not provide one. Use the SDK-supported default
request-timeout mechanism or pass a caller-side deadline, while preserving any
explicitly configured timeout values.
---
Nitpick comments:
In `@agent/sandbox/providers/tenki.py`:
- Around line 490-494: Update _safe_terminate to use
contextlib.suppress(Exception) around sandbox.terminate(), replacing the
try/except/pass pattern while preserving the current behavior of ignoring
termination exceptions.
In `@test/unit_test/agent/sandbox/test_tenki_provider.py`:
- Around line 192-214: Add focused tests alongside
test_tenki_provider_propagates_timeout and
test_tenki_provider_create_maps_quota_error covering SessionTerminatedError and
SessionNotFoundError mapping to RuntimeError, RateLimitedError mapping in
create_instance, and enforcement of max_artifacts, max_artifact_bytes, and
MAX_ARTIFACT_DEPTH. Reuse _FakeSandbox, _build_provider, and the existing
provider APIs, asserting the documented exception types and messages for each
path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c3f6ae7-26f0-431c-9f5d-0c23c7af0895
📒 Files selected for processing (7)
admin/server/services.pyagent/sandbox/client.pyagent/sandbox/providers/__init__.pyagent/sandbox/providers/tenki.pydocs/guides/agent/agent_quickstarts/sandbox_quickstart.mdtest/unit_test/agent/sandbox/test_tenki_provider.pyweb/src/pages/admin/sandbox-settings.tsx
|
Thanks, could you please provide a Go implementation? RAGFlow will be fully migrating to Go starting in August. |
- Add lifecycle logging (init, create, destroy, timeout, terminate failure) using the module logger; never log api_key, project_id, code, or stdout. - Wrap any remaining SDK exception from create/exec in RuntimeError to honor the base-class contract. - Bound control-plane calls (who_am_i, create) with an explicit client request timeout so an unreachable API cannot block indefinitely. - Log terminate failures instead of silently ignoring them. - Add tests for session-terminated/rate-limit/unexpected-error mapping and max_artifacts / max_artifact_bytes enforcement.
Port the tenki provider to the Go sandbox subsystem, mirroring the existing e2b provider: create/exec/destroy against a disposable Tenki microVM via the TenkiCloud Go SDK, with the shared __RAGFLOW_RESULT__ wrapper protocol. Wire it into the provider manager and add TENKI_* env vars. Covered by unit tests plus a key-gated live E2E test.
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
internal/agent/sandbox/tenki.go (1)
17-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove migration-oriented provider documentation.
Describe the current
sandbox.TenkiProviderbehavior directly; remove “Go port” and cross-provider migration comparisons. As per coding guidelines, “keep package and documentation comments aligned with the current runtime path rather than migration history.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/sandbox/tenki.go` around lines 17 - 32, Update the file-level documentation describing sandbox.TenkiProvider to state its current runtime behavior directly. Remove migration-history language such as “Go port,” references to Python or other providers, and cross-provider comparisons, while retaining only accurate details about Tenki’s create/execute/destroy flow, wrapping protocol, artifact behavior, SDK, and configuration.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/agent/sandbox/tenki_test.go`:
- Around line 35-41: Update the test around SupportedLanguages to validate both
directions: retain rejection of unexpected languages and also assert every entry
in the want map appears in the returned langs collection. Ensure missing Python,
JavaScript, or Node.js causes the test to fail.
- Line 256: Update the deferred cleanup around DestroyInstance to use a fresh
bounded cleanup context instead of the test context, capture its returned error,
and fail or report the E2E test when cleanup fails. Preserve cleanup execution
even if the test context is canceled and ensure the cleanup context is released.
In `@internal/agent/sandbox/tenki.go`:
- Around line 90-93: Update the allowOutbound configuration in the sandbox setup
to default to false and enable outbound networking only when ALLOW_OUTBOUND is
explicitly affirmative. Preserve the existing configuration lookup while
ensuring omitted, false, and other non-affirmative values keep networking
disabled.
- Around line 71-100: Update newTenkiProviderFromConfig and TenkiProvider to
retain the configured API key and API URL from cfg, then have Initialize pass
those provider fields to tenkisdk.New instead of requiring process-level
environment values. Keep tenkiConfigFromEnv as the separate environment-backed
path, including its current exclusion of credentials.
- Around line 235-239: Update the transport-error return in the command
execution flow around the visible err check to stop formatting cmd and runArgs
into the error; return a generic tenki transport/session error while preserving
the original err as the wrapped cause.
- Around line 276-280: Update the sess.Close error handling to include
tenkisdk.ErrSessionExpired in the errors.Is checks alongside ErrSessionNotFound
and ErrSessionTerminated, returning nil for all three conditions while
preserving the existing wrapped error for other failures.
---
Nitpick comments:
In `@internal/agent/sandbox/tenki.go`:
- Around line 17-32: Update the file-level documentation describing
sandbox.TenkiProvider to state its current runtime behavior directly. Remove
migration-history language such as “Go port,” references to Python or other
providers, and cross-provider comparisons, while retaining only accurate details
about Tenki’s create/execute/destroy flow, wrapping protocol, artifact behavior,
SDK, and configuration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f28e7519-a1b5-4dc4-9835-82dc9c5790b7
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (8)
agent/sandbox/providers/tenki.pygo.modinternal/agent/sandbox/manager.gointernal/agent/sandbox/provider.gointernal/agent/sandbox/tenki.gointernal/agent/sandbox/tenki_test.gointernal/common/environments.gotest/unit_test/agent/sandbox/test_tenki_provider.py
🚧 Files skipped from review as they are similar to previous changes (1)
- agent/sandbox/providers/tenki.py
Added a Go implementation in |
- Read API key/URL from admin config, not just process env - Default outbound network to opt-in, matching the self_managed sandbox which treats network access as unauthorized by default - Drop wrapped code/args from exec transport-error messages - Treat an expired session as already destroyed on cleanup - Assert the full supported-language set; fail E2E on cleanup error
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
docs/guides/agent/agent_quickstarts/sandbox_quickstart.md (1)
45-47: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winDocument
project_idas a required prerequisite.The provider also rejects initialization without
project_id, which is listed as required below on Line 56. Update this sentence so users do not configure only an API key and then receive an initialization failure.Suggested wording
-... only outbound network access and an API key. +... only outbound network access, an API key, and a project ID.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docs/guides/agent/agent_quickstarts/sandbox_quickstart.md` around lines 45 - 47, Update the Tenki prerequisite sentence near the tenki-sandbox installation guidance to state that both an API key and project_id are required before selecting the provider. Keep the existing dependency and runtime-installation instructions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@docs/guides/agent/agent_quickstarts/sandbox_quickstart.md`:
- Around line 45-47: Update the Tenki prerequisite sentence near the
tenki-sandbox installation guidance to state that both an API key and project_id
are required before selecting the provider. Keep the existing dependency and
runtime-installation instructions unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9be51576-38b3-4f88-b46c-215230c739d6
📒 Files selected for processing (5)
agent/sandbox/providers/tenki.pydocs/guides/agent/agent_quickstarts/sandbox_quickstart.mdinternal/agent/sandbox/tenki.gointernal/agent/sandbox/tenki_test.gotest/unit_test/agent/sandbox/test_tenki_provider.py
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/agent/sandbox/tenki.go
- internal/agent/sandbox/tenki_test.go
- agent/sandbox/providers/tenki.py
- test/unit_test/agent/sandbox/test_tenki_provider.py
| "sync" | ||
| "time" | ||
|
|
||
| tenkisdk "github.com/TenkiCloud/tenki-sdk-go/sandbox" |
There was a problem hiding this comment.
There was a problem hiding this comment.
Migrated to github.com/LuxorLabs/tenki-sdk-go/sandbox v0.5.2.
| // SupportedLanguages returns the languages the default Tenki image can | ||
| // run. The default image ships with python3 and node. | ||
| func (p *TenkiProvider) SupportedLanguages() []string { | ||
| return []string{"python", "nodejs", "javascript"} |
There was a problem hiding this comment.
return []string{"python", "javascript"}
There was a problem hiding this comment.
Done, SupportedLanguages now returns ["python", "javascript"] on both the Go and Python sides.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17305 +/- ##
=======================================
Coverage 90.65% 90.65%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 650 650
Misses 39 39
Partials 28 28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
LGTM |
### Summary Adds a `tenki` sandbox provider that runs each agent code execution in a disposable Tenki (https://tenki.cloud) microVM (create → exec → destroy, no volumes or snapshots). Registration mirrors PR infiniflow#15039, configure `api_key` and `project_id` in Admin > Sandbox Settings. Both runtimes are covered: - Python: `agent/sandbox/providers/tenki.py` (structured results + artifact collection). - Go: `internal/agent/sandbox/tenki.go`, mirroring the e2b provider and wired into the provider manager. `tenki-sandbox` is an optional dependency (it requires `protobuf>=6.31`, which differs from RAGFlow's pinned gRPC stack), lazily imported with a clear error when missing; installation is documented in the sandbox quickstart. Unit tests cover execution, structured results, artifacts (symlink/size/extension limits), non-zero exit, timeout, error mapping, and idempotent destroy. --------- Co-authored-by: yiming.wang <[email protected]>
Walkthrough for RAGFlow's tenki code-execution provider (infiniflow/ragflow#17305): pip install tenki-sandbox, the Admin > Sandbox Settings keys, the ephemeral create/exec/destroy lifecycle, and the artifacts/ contract. verify.py proves the Tenki surface the provider is built on -- who_am_i health check, outbound-off sandbox, python and node execution paths, artifacts/ read-back, terminate -- against the live API, without running RAGFlow. Co-Authored-By: Claude Fable 5 <[email protected]>
Walkthrough for RAGFlow's tenki code-execution provider (infiniflow/ragflow#17305): pip install tenki-sandbox, the Admin > Sandbox Settings keys, the ephemeral create/exec/destroy lifecycle, and the artifacts/ contract. verify.py proves the Tenki surface the provider is built on -- who_am_i health check, outbound-off sandbox, python and node execution paths, artifacts/ read-back, terminate -- against the live API, without running RAGFlow. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Adds a
tenkisandbox provider that runs each agent code execution in a disposable Tenki (https://tenki.cloud) microVM (create → exec → destroy, no volumes or snapshots).Registration mirrors PR #15039, configure
api_keyandproject_idin Admin > Sandbox Settings.Both runtimes are covered:
agent/sandbox/providers/tenki.py(structured results + artifact collection).internal/agent/sandbox/tenki.go, mirroring the e2b provider and wired into the provider manager.tenki-sandboxis an optional dependency (it requiresprotobuf>=6.31, which differs from RAGFlow's pinned gRPC stack), lazily imported with a clear error when missing; installation is documented in the sandbox quickstart.Unit tests cover execution, structured results, artifacts (symlink/size/extension limits), non-zero exit, timeout, error mapping, and idempotent destroy.