mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-28 14:16:34 +08:00
## 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:** - ✅ Aliyun Code Interpreter provider using official `agentrun-sdk>=0.0.16` - ✅ Self-managed provider with gVisor (runsc) security - ✅ Arguments parameter support for dynamic code execution - ✅ Database-only configuration (removed fallback logic) - ✅ Configuration scripts for quick setup Issue #12479 ## Features ### 🔌 Provider Abstraction Layer **1. Self-Managed Provider** (`agent/sandbox/providers/self_managed.py`) - Wraps existing executor_manager HTTP API - gVisor (runsc) for secure container isolation - Configurable pool size, timeout, retry logic - Languages: Python, Node.js, JavaScript - ⚠️ **Requires**: gVisor installation, Docker, base images **2. Aliyun Code Interpreter** (`agent/sandbox/providers/aliyun_codeinterpreter.py`) - SaaS integration using official agentrun-sdk - Serverless microVM execution with auto-authentication - Hard timeout: 30 seconds max - Credentials: `AGENTRUN_ACCESS_KEY_ID`, `AGENTRUN_ACCESS_KEY_SECRET`, `AGENTRUN_ACCOUNT_ID`, `AGENTRUN_REGION` - Automatically wraps code to call `main()` function **3. E2B Provider** (`agent/sandbox/providers/e2b.py`) - Placeholder for future integration ### ⚙️ Configuration System - `conf/system_settings.json`: Default provider = `aliyun_codeinterpreter` - `agent/sandbox/client.py`: Enforces database-only configuration - Admin UI: `/admin/sandbox-settings` - Configuration validation via `validate_config()` method - Health checks for all providers ### 🎯 Key Capabilities **Arguments Parameter Support:** All providers support passing arguments to `main()` function: ```python # User code def main(name: str, count: int) -> dict: return {"message": f"Hello {name}!" * count} # Executed with: arguments={"name": "World", "count": 3} # Result: {"message": "Hello World!Hello World!Hello World!"} ``` **Self-Describing Providers:** Each provider implements `get_config_schema()` returning form configuration for Admin UI **Error Handling:** Structured `ExecutionResult` with stdout, stderr, exit_code, execution_time ## Configuration Scripts Two scripts for quick Aliyun sandbox setup: **Shell Script (requires jq):** ```bash source scripts/configure_aliyun_sandbox.sh ``` **Python Script (interactive):** ```bash python3 scripts/configure_aliyun_sandbox.py ``` ## Testing ```bash # Unit tests uv run pytest agent/sandbox/tests/test_providers.py -v # Aliyun provider tests uv run pytest agent/sandbox/tests/test_aliyun_codeinterpreter.py -v # Integration tests (requires credentials) uv run pytest agent/sandbox/tests/test_aliyun_codeinterpreter_integration.py -v # Quick SDK validation python3 agent/sandbox/tests/verify_sdk.py ``` **Test Coverage:** - 30 unit tests for provider abstraction - Provider-specific tests for Aliyun - Integration tests with real API - Security tests for executor_manager ## Documentation - `docs/develop/sandbox_spec.md` - Complete architecture specification - `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 ## Breaking Changes ⚠️ **Migration Required:** 1. **Directory Move**: `sandbox/` → `agent/sandbox/` - Update imports: `from sandbox.` → `from agent.sandbox.` 2. **Mandatory Configuration**: - SystemSettings must have `sandbox.provider_type` configured - Removed fallback default values - Configuration must exist in database (from `conf/system_settings.json`) 3. **Aliyun Credentials**: - Requires `AGENTRUN_*` environment variables (not `ALIYUN_*`) - `AGENTRUN_ACCOUNT_ID` is now required (Aliyun primary account ID) 4. **Self-Managed Provider**: - gVisor (runsc) must be installed for security - Install: `go install gvisor.dev/gvisor/runsc@latest` ## Database Schema Changes ```python # SystemSettings.value: CharField → TextField api/db/db_models.py: Changed for unlimited config length # SystemSettingsService.get_by_name(): Fixed query precision api/db/services/system_settings_service.py: startswith → exact match ``` ## Files Changed ### Backend (Python) - `agent/sandbox/providers/base.py` - SandboxProvider ABC interface - `agent/sandbox/providers/manager.py` - ProviderManager - `agent/sandbox/providers/self_managed.py` - Self-managed provider - `agent/sandbox/providers/aliyun_codeinterpreter.py` - Aliyun provider - `agent/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 system - `admin/server/services.py` - SandboxMgr with registry & validation - `admin/server/routes.py` - 5 sandbox API endpoints - `conf/system_settings.json` - Default: aliyun_codeinterpreter - `api/db/db_models.py` - TextField for SystemSettings.value - `api/db/services/system_settings_service.py` - Exact match query ### Frontend (TypeScript/React) - `web/src/pages/admin/sandbox-settings.tsx` - Settings UI - `web/src/services/admin-service.ts` - Sandbox service functions - `web/src/services/admin.service.d.ts` - Type definitions - `web/src/utils/api.ts` - Sandbox API endpoints ### Documentation - `docs/develop/sandbox_spec.md` - Architecture spec - `agent/sandbox/tests/MIGRATION_GUIDE.md` - Migration guide - `agent/sandbox/tests/QUICKSTART.md` - Quick start - `agent/sandbox/tests/README.md` - Testing guide ### Configuration Scripts - `scripts/configure_aliyun_sandbox.sh` - Shell script (jq) - `scripts/configure_aliyun_sandbox.py` - Python script ### Tests - `agent/sandbox/tests/test_providers.py` - 30 unit tests - `agent/sandbox/tests/test_aliyun_codeinterpreter.py` - Provider tests - `agent/sandbox/tests/test_aliyun_codeinterpreter_integration.py` - Integration tests - `agent/sandbox/tests/verify_sdk.py` - SDK validation ## Architecture ``` Admin UI → Admin API → SandboxMgr → ProviderManager → [SelfManaged|Aliyun|E2B] ↓ SystemSettings ``` ## Usage ### 1. Configure Provider **Via Admin UI:** 1. Navigate to `/admin/sandbox-settings` 2. Select provider (Aliyun Code Interpreter / Self-Managed) 3. Fill in configuration 4. Click "Test Connection" to verify 5. Click "Save" to apply **Via Configuration Scripts:** ```bash # Aliyun provider export AGENTRUN_ACCESS_KEY_ID="xxx" export AGENTRUN_ACCESS_KEY_SECRET="yyy" export AGENTRUN_ACCOUNT_ID="zzz" export AGENTRUN_REGION="cn-shanghai" source scripts/configure_aliyun_sandbox.sh ``` ### 2. Restart Service ```bash cd docker docker compose restart ragflow-server ``` ### 3. Execute Code in Agent ```python from agent.sandbox.client import execute_code result = execute_code( code='def main(name: str) -> dict: return {"message": f"Hello {name}!"}', language="python", timeout=30, arguments={"name": "World"} ) print(result.stdout) # {"message": "Hello World!"} ``` ## Troubleshooting ### "Container pool is busy" (Self-Managed) - **Cause**: Pool exhausted (default: 1 container in `.env`) - **Fix**: Increase `SANDBOX_EXECUTOR_MANAGER_POOL_SIZE` to 5+ ### "Sandbox provider type not configured" - **Cause**: Database missing configuration - **Fix**: Run config script or set via Admin UI ### "gVisor not found" - **Cause**: runsc not installed - **Fix**: `go install gvisor.dev/gvisor/runsc@latest && sudo cp ~/go/bin/runsc /usr/local/bin/` ### Aliyun authentication errors - **Cause**: Wrong environment variable names - **Fix**: Use `AGENTRUN_*` prefix (not `ALIYUN_*`) ## Checklist - [x] All tests passing (30 unit tests + integration tests) - [x] Documentation updated (spec, migration guide, quickstart) - [x] Type definitions added (TypeScript) - [x] Admin UI implemented - [x] Configuration validation - [x] Health checks implemented - [x] Error handling with structured results - [x] Breaking changes documented - [x] Configuration scripts created - [x] gVisor requirements documented Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
296 lines
10 KiB
JSON
296 lines
10 KiB
JSON
{
|
|
"name": "nodejs",
|
|
"version": "1.0.0",
|
|
"lockfileVersion": 3,
|
|
"requires": true,
|
|
"packages": {
|
|
"": {
|
|
"name": "nodejs",
|
|
"version": "1.0.0",
|
|
"license": "ISC",
|
|
"dependencies": {
|
|
"axios": "^1.9.0"
|
|
}
|
|
},
|
|
"node_modules/asynckit": {
|
|
"version": "0.4.0",
|
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
|
"license": "MIT"
|
|
},
|
|
"node_modules/axios": {
|
|
"version": "1.12.0",
|
|
"resolved": "https://registry.npmjs.org/axios/-/axios-1.12.0.tgz",
|
|
"integrity": "sha512-oXTDccv8PcfjZmPGlWsPSwtOJCZ/b6W5jAMCNcfwJbCzDckwG0jrYJFaWH1yvivfCXjVzV/SPDEhMB3Q+DSurg==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"follow-redirects": "^1.15.6",
|
|
"form-data": "^4.0.4",
|
|
"proxy-from-env": "^1.1.0"
|
|
}
|
|
},
|
|
"node_modules/call-bind-apply-helpers": {
|
|
"version": "1.0.2",
|
|
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
|
|
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"es-errors": "^1.3.0",
|
|
"function-bind": "^1.1.2"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/combined-stream": {
|
|
"version": "1.0.8",
|
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"delayed-stream": "~1.0.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.8"
|
|
}
|
|
},
|
|
"node_modules/delayed-stream": {
|
|
"version": "1.0.0",
|
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">=0.4.0"
|
|
}
|
|
},
|
|
"node_modules/dunder-proto": {
|
|
"version": "1.0.1",
|
|
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
|
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"call-bind-apply-helpers": "^1.0.1",
|
|
"es-errors": "^1.3.0",
|
|
"gopd": "^1.2.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/es-define-property": {
|
|
"version": "1.0.1",
|
|
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
|
|
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/es-errors": {
|
|
"version": "1.3.0",
|
|
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
|
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/es-object-atoms": {
|
|
"version": "1.1.1",
|
|
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
|
|
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"es-errors": "^1.3.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/es-set-tostringtag": {
|
|
"version": "2.1.0",
|
|
"resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz",
|
|
"integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"es-errors": "^1.3.0",
|
|
"get-intrinsic": "^1.2.6",
|
|
"has-tostringtag": "^1.0.2",
|
|
"hasown": "^2.0.2"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/follow-redirects": {
|
|
"version": "1.15.9",
|
|
"resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.9.tgz",
|
|
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
|
|
"funding": [
|
|
{
|
|
"type": "individual",
|
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
|
}
|
|
],
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">=4.0"
|
|
},
|
|
"peerDependenciesMeta": {
|
|
"debug": {
|
|
"optional": true
|
|
}
|
|
}
|
|
},
|
|
"node_modules/form-data": {
|
|
"version": "4.0.4",
|
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
|
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"asynckit": "^0.4.0",
|
|
"combined-stream": "^1.0.8",
|
|
"es-set-tostringtag": "^2.1.0",
|
|
"hasown": "^2.0.2",
|
|
"mime-types": "^2.1.12"
|
|
},
|
|
"engines": {
|
|
"node": ">= 6"
|
|
}
|
|
},
|
|
"node_modules/function-bind": {
|
|
"version": "1.1.2",
|
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
|
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
|
"license": "MIT",
|
|
"funding": {
|
|
"url": "https://github.com/sponsors/ljharb"
|
|
}
|
|
},
|
|
"node_modules/get-intrinsic": {
|
|
"version": "1.3.0",
|
|
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
|
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"call-bind-apply-helpers": "^1.0.2",
|
|
"es-define-property": "^1.0.1",
|
|
"es-errors": "^1.3.0",
|
|
"es-object-atoms": "^1.1.1",
|
|
"function-bind": "^1.1.2",
|
|
"get-proto": "^1.0.1",
|
|
"gopd": "^1.2.0",
|
|
"has-symbols": "^1.1.0",
|
|
"hasown": "^2.0.2",
|
|
"math-intrinsics": "^1.1.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
},
|
|
"funding": {
|
|
"url": "https://github.com/sponsors/ljharb"
|
|
}
|
|
},
|
|
"node_modules/get-proto": {
|
|
"version": "1.0.1",
|
|
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
|
|
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"dunder-proto": "^1.0.1",
|
|
"es-object-atoms": "^1.0.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/gopd": {
|
|
"version": "1.2.0",
|
|
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
|
|
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
},
|
|
"funding": {
|
|
"url": "https://github.com/sponsors/ljharb"
|
|
}
|
|
},
|
|
"node_modules/has-symbols": {
|
|
"version": "1.1.0",
|
|
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
|
|
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
},
|
|
"funding": {
|
|
"url": "https://github.com/sponsors/ljharb"
|
|
}
|
|
},
|
|
"node_modules/has-tostringtag": {
|
|
"version": "1.0.2",
|
|
"resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz",
|
|
"integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"has-symbols": "^1.0.3"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
},
|
|
"funding": {
|
|
"url": "https://github.com/sponsors/ljharb"
|
|
}
|
|
},
|
|
"node_modules/hasown": {
|
|
"version": "2.0.2",
|
|
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
|
|
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"function-bind": "^1.1.2"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/math-intrinsics": {
|
|
"version": "1.1.0",
|
|
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
|
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.4"
|
|
}
|
|
},
|
|
"node_modules/mime-db": {
|
|
"version": "1.52.0",
|
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
|
"license": "MIT",
|
|
"engines": {
|
|
"node": ">= 0.6"
|
|
}
|
|
},
|
|
"node_modules/mime-types": {
|
|
"version": "2.1.35",
|
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
|
"license": "MIT",
|
|
"dependencies": {
|
|
"mime-db": "1.52.0"
|
|
},
|
|
"engines": {
|
|
"node": ">= 0.6"
|
|
}
|
|
},
|
|
"node_modules/proxy-from-env": {
|
|
"version": "1.1.0",
|
|
"resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
|
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
|
"license": "MIT"
|
|
}
|
|
}
|
|
}
|