Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.agentscope.runtime.engine.agents.agentscope.tools.mcp.AsMCPTool;
import io.agentscope.runtime.sandbox.box.Sandbox;
import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.model.container.SandboxType;
import io.agentscope.runtime.sandbox.tools.MCPTool;
import io.agentscope.runtime.sandbox.tools.McpConfigConverter;
import org.slf4j.Logger;
Expand Down Expand Up @@ -299,19 +298,19 @@ public static AgentTool SearchFilesTool(Sandbox sandbox) {
}

public static List<AgentTool> getMcpTools(String serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager) {
return getMcpTools(serverConfigs, sandboxType, sandboxManager, null, null);
}

public static List<AgentTool> getMcpTools(Map<String, Object> serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager) {
return getMcpTools(serverConfigs, sandboxType, sandboxManager, null, null);
}

public static List<AgentTool> getMcpTools(String serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager,
Set<String> whitelist,
Set<String> blacklist) {
Expand All @@ -327,7 +326,7 @@ public static List<AgentTool> getMcpTools(String serverConfigs,
}

public static List<AgentTool> getMcpTools(Map<String, Object> serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager,
Set<String> whitelist,
Set<String> blacklist) {
Expand All @@ -353,7 +352,7 @@ public static List<AgentTool> getMcpTools(Map<String, Object> serverConfigs,
}

// public static List<AgentTool> getAllToolsWithMcp(String mcpServerConfigs,
// SandboxType sandboxType,
// String sandboxType,
// SandboxManager sandboxManager) {
// List<AgentTool> allTools = new ArrayList<>(getAllTools());
//
Expand All @@ -371,7 +370,7 @@ public static List<AgentTool> getMcpTools(Map<String, Object> serverConfigs,
// }

// public static List<AgentTool> getAllToolsWithMcp(Map<String, Object> mcpServerConfigs,
// SandboxType sandboxType,
// String sandboxType,
// SandboxManager sandboxManager) {
// List<AgentTool> allTools = new ArrayList<>(getAllTools());
//
Expand All @@ -389,7 +388,7 @@ public static List<AgentTool> getMcpTools(Map<String, Object> serverConfigs,
// }

public static List<MCPTool> createMcpToolInstances(String serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager) {
McpConfigConverter converter = McpConfigConverter.builder()
.serverConfigs(serverConfigs)
Expand All @@ -401,7 +400,7 @@ public static List<MCPTool> createMcpToolInstances(String serverConfigs,
}

public static List<MCPTool> createMcpToolInstances(Map<String, Object> serverConfigs,
SandboxType sandboxType,
String sandboxType,
SandboxManager sandboxManager) {
McpConfigConverter converter = McpConfigConverter.builder()
.serverConfigs(serverConfigs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.agentscope.core.message.ToolResultBlock;
import io.agentscope.runtime.engine.agents.agentscope.tools.AgentScopeSandboxAwareTool;
import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.model.container.SandboxType;
import io.agentscope.runtime.sandbox.tools.MCPTool;
import reactor.core.publisher.Mono;

Expand All @@ -29,7 +28,7 @@
public class AsMCPTool extends AgentScopeSandboxAwareTool<MCPTool> {
public AsMCPTool(String name, String toolType, String description,
Map<String, Object> schema, Map<String, Object> serverConfigs,
SandboxType sandboxType, SandboxManager sandboxManager) {
String sandboxType, SandboxManager sandboxManager) {
super(new MCPTool(name,
toolType,
description,
Expand Down
79 changes: 33 additions & 46 deletions cookbook/en/sandbox/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

#### ManagerConfig Configuration

| Parameter | Type | Description | Default | Notes |
| ----------------------| ------------ | ---------------------- | -------------------------- | ------------------------------------------------------------ |
| `defaultSandboxType` | `List<SandboxType>` | Default sandbox type(s) (can be multiple) | `SandboxType.BASE` | Can be a single type or a list of multiple types, enabling multiple independent sandbox warm-up pools. Valid values include `BASE`, `BROWSER`, `FILESYSTEM`, `GUI`, etc. |
| `bearerToken` | `String` | Authentication token for calling remote runtime sandbox | `null` | If set to `null`, no authentication will be performed when connecting |
| `baseUrl` | `String` | Server binding address for calling remote runtime sandbox | `null` | If set to `null`, local sandbox management will be used by default |
| `containerDeployment` | `BaseClientConfig` | Container runtime | `DockerClientConfig` | Currently supports `Docker`, `K8s`, and `AgentRun` |
| `poolSize` | `int` | Warm-up container pool size | `0` | Cached containers for faster startup. The `poolSize` parameter controls the number of pre-created containers cached in ready state. When a user requests a new sandbox, the system will first try to allocate from this warm-up pool, significantly reducing startup time compared to creating containers from scratch. For example, with `poolSize=10`, the system maintains 10 ready containers that can be immediately assigned to new requests |
| `fileSystemConfig` | `FileSystemConfig` | Container file system configuration | `LocalFileSystemConfig` | Manages container file system download method, defaults to `local file system`, can also use `oss` |
| Parameter | Type | Description | Default | Notes |
| ----------------------|----------------------| ---------------------- | -------------------------- | ------------------------------------------------------------ |
| `defaultSandboxType` | `List<String>` | Default sandbox type(s) (can be multiple) | `SandboxType.BASE` | Can be a single type or a list of multiple types, enabling multiple independent sandbox warm-up pools. Valid values include `BASE`, `BROWSER`, `FILESYSTEM`, `GUI`, etc. |
| `bearerToken` | `String` | Authentication token for calling remote runtime sandbox | `null` | If set to `null`, no authentication will be performed when connecting |
| `baseUrl` | `String` | Server binding address for calling remote runtime sandbox | `null` | If set to `null`, local sandbox management will be used by default |
| `containerDeployment` | `BaseClientConfig` | Container runtime | `DockerClientConfig` | Currently supports `Docker`, `K8s`, and `AgentRun` |
| `poolSize` | `int` | Warm-up container pool size | `0` | Cached containers for faster startup. The `poolSize` parameter controls the number of pre-created containers cached in ready state. When a user requests a new sandbox, the system will first try to allocate from this warm-up pool, significantly reducing startup time compared to creating containers from scratch. For example, with `poolSize=10`, the system maintains 10 ready containers that can be immediately assigned to new requests |
| `fileSystemConfig` | `FileSystemConfig` | Container file system configuration | `LocalFileSystemConfig` | Manages container file system download method, defaults to `local file system`, can also use `oss` |
| `redisConfig` | `RedisManagerConfig` | Redis support configuration | `null` | Enable Redis support, required for distributed deployment or when number of worker processes is greater than `1`, disabled by default |

#### Redis Configuration
Expand Down Expand Up @@ -149,47 +149,34 @@ pip install -e .

### Creating Custom Sandbox Class

You can define custom sandbox types and register them with the system to meet special requirements. Simply inherit from `Sandbox` and use the `SandboxRegistry.register` decorator, then place the file in `src/agentscope_runtime/sandbox/custom` (e.g., `src/agentscope_runtime/sandbox/custom/custom_sandbox.py`):
You can define custom sandbox types and register them with the system to meet special requirements. Simply inherit from the `Sandbox` class and use the `@RegisterSandbox` decorator, then place the file within your project folder:

```python
import os
```java
import io.agentscope.runtime.sandbox.box.Sandbox;
import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.registry.RegisterSandbox;

from typing import Optional

from agentscope_runtime.sandbox.utils import build_image_uri
from agentscope_runtime.sandbox.registry import SandboxRegistry
from agentscope_runtime.sandbox.enums import SandboxType
from agentscope_runtime.sandbox.box.sandbox import Sandbox

SANDBOXTYPE = "my_custom_sandbox"


@SandboxRegistry.register(
build_image_uri(f"runtime-sandbox-{SANDBOXTYPE}"),
sandbox_type=SANDBOXTYPE,
security_level="medium",
timeout=60,
description="my sandbox",
environment={
"TAVILY_API_KEY": os.getenv("TAVILY_API_KEY", ""),
"AMAP_MAPS_API_KEY": os.getenv("AMAP_MAPS_API_KEY", ""),
},
@RegisterSandbox(
imageName = "YOUR-IMAGE-NAME",
sandboxType = "CustomSandboxType",
securityLevel = "medium",
timeout = 30,
description = "YOUR Sandbox"
)
class MyCustomSandbox(Sandbox):
def __init__(
self,
sandbox_id: Optional[str] = None,
timeout: int = 3000,
base_url: Optional[str] = None,
bearer_token: Optional[str] = None,
):
super().__init__(
sandbox_id,
timeout,
base_url,
bearer_token,
SandboxType(SANDBOXTYPE),
)
public class CustomSandbox extends Sandbox {

public CustomSandbox(SandboxManager managerApi, String userId, String sessionId) {
this(managerApi, userId, sessionId, 3000);
}

public CustomSandbox(
SandboxManager managerApi,
String userId,
String sessionId,
int timeout) {
super(managerApi, userId, sessionId, "CustomSandboxType", timeout);
}
}
```

### Prepare Docker Image
Expand Down
9 changes: 4 additions & 5 deletions cookbook/zh/sandbox/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#### ManagerConfig 配置

| Parameter | Type | Description | Default | Notes |
| --------------------- | -------------------- | ----------------------------------- | ----------------------- | ------------------------------------------------------------ |
| `defaultSandboxType` | `List<SandboxType>` | 默认沙箱类型(可多个) | `SandboxType.BASE` | 可以是单个类型,也可以是多个类型的列表,从而启用多个独立的沙箱预热池。合法取值包括 `BASE`、`BROWSER`、`FILESYSTEM`、`GUI` 等 |
| --------------------- |----------------------| ----------------------------------- | ----------------------- | ------------------------------------------------------------ |
| `defaultSandboxType` | `List<String>` | 默认沙箱类型(可多个) | `SandboxType.BASE` | 可以是单个类型,也可以是多个类型的列表,从而启用多个独立的沙箱预热池。合法取值包括 `BASE`、`BROWSER`、`FILESYSTEM`、`GUI` 等 |
| `bearerToken` | `String` | 调用远程runtime沙箱的身份验证令牌 | `null` | 如果设置为 `null`,将在连接的时候不会进行身份验证 |
| `baseUrl` | `String` | 调用远程runtime沙箱的服务器绑定地址 | `null` | 如果设置为 `null`,将默认使用本地沙箱管理 |
| `containerDeployment` | `BaseClientConfig` | 容器运行时 | `DockerClientConfig` | 目前支持 `Docker`、`K8s` 和 `AgentRun` |
Expand Down Expand Up @@ -178,12 +178,11 @@ pip install -e .
```java
import io.agentscope.runtime.sandbox.box.Sandbox;
import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.model.container.SandboxType;
import io.agentscope.runtime.sandbox.manager.registry.RegisterSandbox;

@RegisterSandbox(
imageName = "YOUR-IMAGE-NAME",
sandboxType = SandboxType.CUSTOM,
sandboxType = "CustomSandboxType",
securityLevel = "medium",
timeout = 30,
description = "YOUR Sandbox"
Expand All @@ -199,7 +198,7 @@ public class CustomSandbox extends Sandbox {
String userId,
String sessionId,
int timeout) {
super(managerApi, userId, sessionId, SandboxType.CUSTOM, timeout);
super(managerApi, userId, sessionId, "CustomSandboxType", timeout);
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package io.agentscope.runtime.sandbox.box;

import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.model.container.SandboxType;

public abstract class CloudSandbox extends Sandbox {
public CloudSandbox(SandboxManager managerApi, String userId, String sessionId, SandboxType sandboxType) {
public CloudSandbox(SandboxManager managerApi, String userId, String sessionId, String sandboxType) {
this(managerApi, userId, sessionId, 3000, sandboxType);
}

Expand All @@ -29,7 +28,7 @@ public CloudSandbox(
String userId,
String sessionId,
int timeout,
SandboxType sandboxType) {
String sandboxType) {
super(managerApi, userId, sessionId, sandboxType, timeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DummySandbox implements AutoCloseable {
private final String sandboxId;
private final String userId;
private final String sessionId;
private final SandboxType sandboxType;
private final String sandboxType;
private boolean closed = false;

public DummySandbox(SandboxManager managerApi, String userId, String sessionId) {
Expand Down Expand Up @@ -63,7 +63,7 @@ public String getSessionId() {
return sessionId;
}

public SandboxType getSandboxType() {
public String getSandboxType() {
return sandboxType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class Sandbox implements AutoCloseable {
protected String sandboxId;
protected final String userId;
protected final String sessionId;
protected final SandboxType sandboxType;
protected final String sandboxType;
protected final int timeout;
protected final boolean autoRelease;
protected boolean closed = false;
Expand All @@ -39,7 +39,7 @@ public Sandbox(
SandboxManager managerApi,
String userId,
String sessionId,
SandboxType sandboxType,
String sandboxType,
int timeout) {
this(managerApi, userId, sessionId, sandboxType, timeout, true);
}
Expand All @@ -48,7 +48,7 @@ public Sandbox(
SandboxManager managerApi,
String userId,
String sessionId,
SandboxType sandboxType,
String sandboxType,
int timeout,
boolean autoRelease) {
this.managerApi = managerApi;
Expand Down Expand Up @@ -87,7 +87,7 @@ public String getSessionId() {
return sessionId;
}

public SandboxType getSandboxType() {
public String getSandboxType() {
return sandboxType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.agentscope.runtime.sandbox.box;

import io.agentscope.runtime.sandbox.manager.SandboxManager;
import io.agentscope.runtime.sandbox.manager.model.container.SandboxType;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -27,15 +26,15 @@ public TrainingSandbox(
SandboxManager managerApi,
String userId,
String sessionId,
SandboxType sandboxType) {
String sandboxType) {
this(managerApi, userId, sessionId, sandboxType, 3000);
}

public TrainingSandbox(
SandboxManager managerApi,
String userId,
String sessionId,
SandboxType sandboxType,
String sandboxType,
int timeout) {
super(managerApi, userId, sessionId, sandboxType, timeout);
}
Expand Down
Loading
Loading