AS AgentScopeAPI 手册 / API Reference

SandboxConnector

public class SandboxConnector
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:44–330

沙箱 Connector,在隔离环境中安全执行代码和工具。位于 io.agentscope.extensions.sandbox.kubernetes.client.internal 包。核心成员包括 connect、close、isConnected、getStrategy、sendRequest、sendRequestForBytes。

Manages HTTP connectivity to the sandbox (via router or in-cluster), including URL discovery, retry logic, and header injection.

构造器摘要Constructor Summary

构造器Constructor说明Description
public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier)
初始化 `SandboxConnector` 实例。
Creates a new instance.
public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier, Duration requestTimeout, Duration perAttemptTimeout)
初始化 `SandboxConnector` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public void connect() throws Exception
建立连接并完成初始化。
Discovers the base URL via the connection strategy.
public void close()
关闭连接并释放相关资源。
Tears down the transport.
public boolean isConnected()
判断是否已连接。
Returns whether the connected.
public ConnectionStrategy getStrategy()
获取 `getStrategy`。
Returns the strategy.
public HttpResponse<String> sendRequest(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType, int maxRetries) throws IOException, InterruptedException
发送请求。
Sends an HTTP request with retry logic and optional sandbox headers.
public HttpResponse<byte[]> sendRequestForBytes(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType) throws IOException, InterruptedException
发送请求用于字节。
Sends a request and returns the raw byte response (for file downloads).

构造器详情Constructor Detail

SandboxConnector

public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier)

初始化 SandboxConnector 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
sandboxIdString沙箱标识(类型 `String`)。The sandbox id.
namespaceString命名空间(类型 `String`)。The namespace.
connectionConfigSandboxConnectionConfig连接配置(类型 `SandboxConnectionConfig`)。The connection config.
k8sHelperK8sHelperk 8 s Helper(类型 `K8sHelper`)。The k 8 s helper.
podIpSupplierSupplier<String>pod Ip Supplier(类型 `Supplier`)。The pod ip supplier.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:64–71

SandboxConnector

public SandboxConnector(String sandboxId, String namespace, SandboxConnectionConfig connectionConfig, K8sHelper k8sHelper, Supplier<String> podIpSupplier, Duration requestTimeout, Duration perAttemptTimeout)

初始化 SandboxConnector 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
sandboxIdString沙箱标识(类型 `String`)。The sandbox id.
namespaceString命名空间(类型 `String`)。The namespace.
connectionConfigSandboxConnectionConfig连接配置(类型 `SandboxConnectionConfig`)。The connection config.
k8sHelperK8sHelperk 8 s Helper(类型 `K8sHelper`)。The k 8 s helper.
podIpSupplierSupplier<String>pod Ip Supplier(类型 `Supplier`)。The pod ip supplier.
requestTimeoutDuration请求超时(类型 `Duration`)。The request timeout.
perAttemptTimeoutDuration每个尝试超时(类型 `Duration`)。The per attempt timeout.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:73–97

方法详情Method Detail

connect

public void connect() throws Exception

建立连接并完成初始化。

Discovers the base URL via the connection strategy.

抛出Throws
  • Exception 可能抛出 `Exception`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:150–155

close

public void close()

关闭连接并释放相关资源。

Tears down the transport.

源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:158–165

isConnected

public boolean isConnected()

判断是否已连接。

Returns whether the connected.

返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:167–169

getStrategy

public ConnectionStrategy getStrategy()

获取 getStrategy。

Returns the strategy.

返回Returns ConnectionStrategy
返回ConnectionStrategy。Returns connection strategy.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:171–173

sendRequest

public HttpResponse<String> sendRequest(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType, int maxRetries) throws IOException, InterruptedException

发送请求。

Sends an HTTP request with retry logic and optional sandbox headers.

参数Parameters
名称Name类型Type说明Description
methodString方法(类型 `String`)。HTTP method
endpointString端点地址(类型 `String`)。path relative to base URL
bodyHttpRequest.BodyPublisher正文(类型 `HttpRequest.BodyPublisher`)。request body, or null for GET
contentTypeString内容类型(类型 `String`)。content type header
maxRetriesint最大重试(类型 `int`)。max attempts (0 = default)
返回Returns HttpResponse<String>
返回HttpResponse。HTTP response
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:185–239

sendRequestForBytes

public HttpResponse<byte[]> sendRequestForBytes(String method, String endpoint, HttpRequest.BodyPublisher body, String contentType) throws IOException, InterruptedException

发送请求用于字节。

Sends a request and returns the raw byte response (for file downloads).

参数Parameters
名称Name类型Type说明Description
methodString方法(类型 `String`)。HTTP method
endpointString端点地址(类型 `String`)。path
bodyHttpRequest.BodyPublisher正文(类型 `HttpRequest.BodyPublisher`)。body or null
contentTypeString内容类型(类型 `String`)。content type
返回Returns HttpResponse<byte[]>
返回HttpResponse。byte response
抛出Throws
  • IOException 可能抛出 `IOException`。Thrown when the operation cannot be completed.
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/extensions/sandbox/kubernetes/client/internal/SandboxConnector.java:250–261
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.