Repository navigation
feat: Implement pluggable multi-provider sandbox architecture - #12820
Merged
Merged
Conversation
yuzhichang
marked this pull request as draft
January 26, 2026 08:23
yuzhichang
force-pushed
the
sandbox_saas
branch
2 times, most recently
from
January 27, 2026 09:24
7381936 to
d4e8507
Compare
yuzhichang
marked this pull request as ready for review
January 27, 2026 09:28
yuzhichang
added a commit
to yuzhichang/ragflow
that referenced
this pull request
Jan 27, 2026
- Remove unused imports and variables in provider implementations * Remove unused template_name assignment in aliyun_codeinterpreter.py * Remove unused time import in e2b.py * Remove unused MagicMock import in test_providers.py * Add noqa comments for SDK availability checks in verify_sdk.py - Delete MIGRATION_GUIDE.md and QUICKSTART.md (consolidated into main README) - Update agent/sandbox/tests/README.md with accurate information: * Correct environment variable names (AGENTRUN_* not ALIYUN_*) * Add SDK validation section * Add self-managed provider testing instructions * Add troubleshooting for common issues * Update provider-specific notes and references Fixes CI ruff linting failures in PR infiniflow#12820
Add a flexible sandbox provider system supporting both self-managed and SaaS
backends for secure code execution in agent workflows.
- `agent/sandbox/providers/base.py`: SandboxProvider ABC interface with
SandboxInstance and ExecutionResult dataclasses
- `agent/sandbox/providers/manager.py`: ProviderManager for active provider
management
- `agent/sandbox/client.py`: Unified client with automatic provider loading
from SystemSettings (enforces database-only configuration)
- `agent/tools/code_exec.py`: Updated to use provider system with backward
compatibility fallback
1. **Self-Managed Provider** (`agent/sandbox/providers/self_managed.py`):
- Wraps existing executor_manager HTTP API
- Supports gVisor (runsc) for secure container isolation
- Configurable pool size, timeout, and retry logic
- Requires: gVisor installation, Docker, base images
2. **Aliyun Code Interpreter** (`agent/sandbox/providers/aliyun_codeinterpreter.py`):
- SaaS integration using official agentrun-sdk>=0.0.16
- Serverless microVM execution with automatic authentication
- Code wrapping to call main() function with arguments support
- Required: AGENTRUN_ACCESS_KEY_ID, AGENTRUN_ACCESS_KEY_SECRET,
AGENTRUN_ACCOUNT_ID, AGENTRUN_REGION
3. **E2B Provider** (`agent/sandbox/providers/e2b.py`):
- Placeholder for future E2B integration
- `conf/system_settings.json`: Default provider configuration
(provider_type: aliyun_codeinterpreter)
- `api/db/services/system_settings_service.py`: Fixed exact match query
(startswith → exact match for setting name lookup)
- `api/db/db_models.py`: Changed SystemSettings.value to TextField
for unlimited config length
- `admin/server/services.py`: SandboxMgr with provider registry,
config validation, and connection testing
- `admin/server/routes.py`: 5 admin API endpoints for sandbox management
- `web/src/pages/admin/sandbox-settings.tsx`: Comprehensive settings UI
with provider selection, dynamic forms, and testing
- `agent/sandbox/tests/test_providers.py`: 30 unit tests
- `agent/sandbox/tests/test_aliyun_codeinterpreter.py`: Provider-specific tests
- `agent/sandbox/tests/test_aliyun_codeinterpreter_integration.py`: Integration tests
- `agent/sandbox/tests/verify_sdk.py`: Quick SDK validation script
- `docs/develop/sandbox_spec.md`: Complete architecture specification
with provider details, configuration format, and troubleshooting
- `agent/sandbox/tests/MIGRATION_GUIDE.md`: Migration from legacy sandbox
- `agent/sandbox/tests/QUICKSTART.md`: Quick start guide
- `agent/sandbox/tests/README.md`: Testing documentation
- **Arguments Parameter**: All providers support passing arguments to main()
function for dynamic code execution
- **Self-Describing Providers**: get_config_schema() returns form configuration
- **Config Validation**: validate_config() method for provider-specific checks
- **Health Checks**: All providers implement health_check() method
- **Error Handling**: Structured ExecutionResult with stdout, stderr, exit_code
- `scripts/configure_aliyun_sandbox.sh`: Shell script (jq) for quick setup
- `scripts/configure_aliyun_sandbox.py`: Python script for interactive setup
- `agent/sandbox/` directory moved from `sandbox/`
- SystemSettings must have `sandbox.provider_type` configured (removed fallback)
- Aliyun credentials require AGENTRUN_* environment variables
- Self-managed provider requires gVisor (runsc) for security
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
yuzhichang
force-pushed
the
sandbox_saas
branch
from
January 28, 2026 01:54
30dc551 to
e8a9aa1
Compare
- Remove unused variable `template_name` in aliyun_codeinterpreter.py - Remove unused variables `normalized_lang`, `execution_time`, and `start_time` in e2b.py - Remove unused `time` import in e2b.py - Remove unused `MagicMock` import in test_providers.py - Fix unused imports in verify_sdk.py by using importlib.util.find_spec This fixes CI ruff check failures: - F841: Local variables assigned but never used - F401: Imports unused Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Member
Author
CI FixJust pushed a commit to fix the ruff linting errors:
All ruff checks should now pass ✅ |
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.
Summary
Implement a flexible sandbox provider system supporting both self-managed (Docker) and SaaS (Aliyun Code Interpreter) backends for secure code execution in agent workflows.
Key Changes:
agentrun-sdk>=0.0.16Issue #12479
Features
🔌 Provider Abstraction Layer
1. Self-Managed Provider (
agent/sandbox/providers/self_managed.py)2. Aliyun Code Interpreter (
agent/sandbox/providers/aliyun_codeinterpreter.py)AGENTRUN_ACCESS_KEY_ID,AGENTRUN_ACCESS_KEY_SECRET,AGENTRUN_ACCOUNT_ID,AGENTRUN_REGIONmain()function3. E2B Provider (
agent/sandbox/providers/e2b.py)⚙️ Configuration System
conf/system_settings.json: Default provider =aliyun_codeinterpreteragent/sandbox/client.py: Enforces database-only configuration/admin/sandbox-settingsvalidate_config()method🎯 Key Capabilities
Arguments Parameter Support:
All providers support passing arguments to
main()function:Self-Describing Providers:
Each provider implements
get_config_schema()returning form configuration for Admin UIError Handling:
Structured
ExecutionResultwith stdout, stderr, exit_code, execution_timeConfiguration Scripts
Two scripts for quick Aliyun sandbox setup:
Shell Script (requires jq):
source scripts/configure_aliyun_sandbox.shPython Script (interactive):
Testing
Test Coverage:
Documentation
docs/develop/sandbox_spec.md- Complete architecture specificationagent/sandbox/tests/MIGRATION_GUIDE.md- Migration from legacy sandboxagent/sandbox/tests/QUICKSTART.md- Quick start guideagent/sandbox/tests/README.md- Testing documentationBreaking Changes
Directory Move:
sandbox/→agent/sandbox/from sandbox.→from agent.sandbox.Mandatory Configuration:
sandbox.provider_typeconfiguredconf/system_settings.json)Aliyun Credentials:
AGENTRUN_*environment variables (notALIYUN_*)AGENTRUN_ACCOUNT_IDis now required (Aliyun primary account ID)Self-Managed Provider:
go install gvisor.dev/gvisor/runsc@latestDatabase Schema Changes
Files Changed
Backend (Python)
agent/sandbox/providers/base.py- SandboxProvider ABC interfaceagent/sandbox/providers/manager.py- ProviderManageragent/sandbox/providers/self_managed.py- Self-managed provideragent/sandbox/providers/aliyun_codeinterpreter.py- Aliyun provideragent/sandbox/providers/e2b.py- E2B provider (placeholder)agent/sandbox/client.py- Unified client (enforces DB-only config)agent/tools/code_exec.py- Updated to use provider systemadmin/server/services.py- SandboxMgr with registry & validationadmin/server/routes.py- 5 sandbox API endpointsconf/system_settings.json- Default: aliyun_codeinterpreterapi/db/db_models.py- TextField for SystemSettings.valueapi/db/services/system_settings_service.py- Exact match queryFrontend (TypeScript/React)
web/src/pages/admin/sandbox-settings.tsx- Settings UIweb/src/services/admin-service.ts- Sandbox service functionsweb/src/services/admin.service.d.ts- Type definitionsweb/src/utils/api.ts- Sandbox API endpointsDocumentation
docs/develop/sandbox_spec.md- Architecture specagent/sandbox/tests/MIGRATION_GUIDE.md- Migration guideagent/sandbox/tests/QUICKSTART.md- Quick startagent/sandbox/tests/README.md- Testing guideConfiguration Scripts
scripts/configure_aliyun_sandbox.sh- Shell script (jq)scripts/configure_aliyun_sandbox.py- Python scriptTests
agent/sandbox/tests/test_providers.py- 30 unit testsagent/sandbox/tests/test_aliyun_codeinterpreter.py- Provider testsagent/sandbox/tests/test_aliyun_codeinterpreter_integration.py- Integration testsagent/sandbox/tests/verify_sdk.py- SDK validationArchitecture
Usage
1. Configure Provider
Via Admin UI:
/admin/sandbox-settingsVia Configuration Scripts:
2. Restart Service
cd docker docker compose restart ragflow-server3. Execute Code in Agent
Troubleshooting
"Container pool is busy" (Self-Managed)
.env)SANDBOX_EXECUTOR_MANAGER_POOL_SIZEto 5+"Sandbox provider type not configured"
"gVisor not found"
go install gvisor.dev/gvisor/runsc@latest && sudo cp ~/go/bin/runsc /usr/local/bin/Aliyun authentication errors
AGENTRUN_*prefix (notALIYUN_*)Checklist
Co-Authored-By: Claude Sonnet 4.5 [email protected]