You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mkdocs/en/code_executor.md
+242-4Lines changed: 242 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ When this feature is enabled, if the LLM returns text containing code snippets,
6
6
7
7
## Code Executor Types
8
8
9
-
Two types of code executors are currently available:
9
+
Three types of code executors are currently available:
10
10
11
11
### UnsafeLocalCodeExecutor
12
12
@@ -34,6 +34,21 @@ Two types of code executors are currently available:
34
34
- Scenarios requiring execution of untrusted code
35
35
- Scenarios requiring environment isolation
36
36
37
+
### CubeCodeExecutor
38
+
39
+
**Features:**
40
+
- Agent dispatches code snippets to a remote Cube/E2B sandbox for execution; supports `Python/Bash`
41
+
- Strong sandboxed environment running on a remote host, suitable for executing untrusted code at scale
42
+
- Decoupled lifecycle: the same sandbox can be re-attached across processes via `sandbox_id` (`create` / `attach` / `create_or_recreate` factories)
43
+
- Ships an optional `CubeWorkspaceRuntime` that adds per-execution workspace directories, file upload/download (single files or whole directories via tar), and structured program runs — useful for the Skill subsystem
44
+
- Requires the optional `[cube]` extra (`pip install 'trpc-agent-py[cube]'`, which installs `e2b-code-interpreter`) and access to a Cube/E2B-compatible gateway
45
+
46
+
**Use Cases:**
47
+
- Production environments where Docker is not available on the agent host
48
+
- Scenarios requiring strong remote isolation for untrusted code
49
+
- Long-lived skill/code execution that needs a persistent workspace surviving across multiple `execute_code` calls
50
+
- Multi-tenant agent platforms that share a remote sandbox fleet
51
+
37
52
## Usage Examples
38
53
39
54
When creating an LlmAgent, build a CodeExecutor and configure the `code_executor` parameter to enable code execution functionality.
@@ -48,15 +63,19 @@ from trpc_agent_sdk.models import OpenAIModel
48
63
from trpc_agent_sdk.code_executors import BaseCodeExecutor
49
64
from trpc_agent_sdk.code_executors import UnsafeLocalCodeExecutor
50
65
from trpc_agent_sdk.code_executors import ContainerCodeExecutor
66
+
# Cube is an optional extra (`pip install 'trpc-agent-py[cube]'`)
67
+
from trpc_agent_sdk.code_executors.cube import CubeCodeExecutor
68
+
from trpc_agent_sdk.code_executors.cube import CubeCodeExecutorConfig
1.**Production Environment**: It is strongly recommended to use `ContainerCodeExecutor` for sandbox isolation
@@ -307,4 +544,5 @@ See the complete example code: [examples/code_executors/agent/agent.py](../../..
307
544
308
545
-**UnsafeLocalCodeExecutor**: Fast execution speed, suitable for rapid iteration
309
546
-**ContainerCodeExecutor**: The initial startup requires pulling the image; subsequent executions are relatively fast
310
-
- It is recommended to use ContainerCodeExecutor in production environments and UnsafeLocalCodeExecutor in development environments
547
+
-**CubeCodeExecutor**: Adds network round-trips to a remote sandbox per command, but amortizes well for long-lived sessions because the sandbox is reused across calls (and across processes via `sandbox_id`); workspace file transfers use a tar-based protocol so directory uploads/downloads stay a single round-trip
548
+
- It is recommended to use ContainerCodeExecutor or CubeCodeExecutor in production environments and UnsafeLocalCodeExecutor in development environments
- Executes inside a remote Cube/E2B sandbox; suitable for environments without local Docker, or when strong remote isolation is required
1084
+
- Construct via `create_cube_workspace_runtime(executor, workspace_cfg=...)`; see [code_executor.md](code_executor.md#cubeworkspaceruntime) for details
1085
+
- Requires the optional `[cube]` extra (`pip install 'trpc-agent-py[cube]'`) and the `E2B_API_URL` / `E2B_API_KEY` / `CUBE_TEMPLATE_ID` environment variables (or equivalent cfg fields)
1076
1086
1077
1087
**Container executor notes**:
1078
1088
- The run base directory is writable; when `$SKILLS_ROOT` is set, it is mounted in read-only mode
1079
1089
- Network access is disabled by default for reproducibility and security
1080
1090
1091
+
**Cube executor notes**:
1092
+
- File and directory transfers use a tar-based protocol so directory upload/download stays a single round-trip and preserves symlinks/permissions
1093
+
- The remote workspace root defaults to `/workspace/cube_agent`; per-execution subtrees follow the `ws_<exec_id>_<suffix>` naming convention and are recreated lazily on every `create_workspace` call (so external sandbox cleanup heals transparently)
1094
+
- The same Cube sandbox can back both the bare `CubeCodeExecutor` and the workspace runtime; commands share `execute_timeout` from `CubeCodeExecutorConfig`
1095
+
1081
1096
**Security and resource limits**:
1082
1097
-**Workspace isolation**: All read/write operations are confined within the workspace
1083
1098
-**Risk control**: Reduces security risks through timeout mechanisms and read-only skill trees
0 commit comments