AS AgentScopeAPI 手册 / API Reference

SandboxExecutionGuard

@FunctionalInterface public interface SandboxExecutionGuard
源码Source io/agentscope/harness/agent/sandbox/SandboxExecutionGuard.java:58–94

定义沙箱执行守卫契约的接口。位于 io.agentscope.harness.agent.sandbox 包。核心成员包括 tryEnter、noop。

Pluggable concurrency guard for sandbox execution slots.

A guard controls how many concurrent executions are allowed for a given SandboxIsolationKey. The default #noop() imposes no restriction, preserving existing behaviour.

This extension point is primarily useful for IsolationScope#USER, IsolationScope#AGENT and IsolationScope#GLOBAL scopes, where multiple concurrent callers could otherwise race on the same persistent state slot (last write wins). Providing a guard serialises such callers without requiring changes to the surrounding infrastructure.

Implementations may use any backend — JVM semaphores, Redis SET NX leases, ZooKeeper, database advisory locks, etc. — and must be thread-safe.

Usage

`SandboxExecutionGuard guard = key -> {
redisClient.set(key.toString(), token, SetArgs.Builder.nx().px(30_000));
return () -> redisClient.eval(LUA_RELEASE_SCRIPT, key.toString(), token);
};

HarnessAgent.builder()
.filesystem(new DockerFilesystemSpec()
.isolationScope(IsolationScope.AGENT)
.executionGuard(guard))
...
.build();
`

Lifecycle

The harness calls #tryEnter before sandbox acquire/resume and closes the returned SandboxLease after SandboxManager#release completes, so the guard covers the full call window: acquire → start → (call) → stop → release → lease.close().

嵌套类摘要Nested Class Summary

类Class类型Kind说明Description
NoopSandboxExecutionGuard类class
Noop 沙箱执行守卫,承载智能体的部署、调度与服务化运行。
Singleton no-op implementation.

方法摘要Method Summary

方法Method说明Description
public SandboxLease tryEnter(SandboxIsolationKey key) throws InterruptedException
设置该参数。
Acquires the execution right for the given isolation key, blocking until the slot becomes available or the calling thread is interrupted.
static public SandboxExecutionGuard noop()
static
返回 `noop` 结果。
Returns the default no-op guard: execution is always allowed immediately and the returned `SandboxLease` is a no-op.

方法详情Method Detail

tryEnter

public SandboxLease tryEnter(SandboxIsolationKey key) throws InterruptedException

设置该参数。

Acquires the execution right for the given isolation key, blocking until the slot becomes available or the calling thread is interrupted.

参数Parameters
名称Name类型Type说明Description
keySandboxIsolationKey键(类型 `SandboxIsolationKey`)。the isolation key that identifies the sandbox slot to protect
返回Returns SandboxLease
返回SandboxLease。a lease that releases the execution right when closed
抛出Throws
  • InterruptedException 可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
源码Source io/agentscope/harness/agent/sandbox/SandboxExecutionGuard.java:72

noop

static public SandboxExecutionGuard noop()
static

返回 noop 结果。

Returns the default no-op guard: execution is always allowed immediately and the returned SandboxLease is a no-op.

返回Returns SandboxExecutionGuard
返回SandboxExecutionGuard。Returns sandbox execution guard.
源码Source io/agentscope/harness/agent/sandbox/SandboxExecutionGuard.java:78–80

嵌套类详情Nested Class Detail

NoopSandboxExecutionGuard

final class NoopSandboxExecutionGuard implements SandboxExecutionGuard

Noop 沙箱执行守卫,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.sandbox 包,实现 SandboxExecutionGuard。核心成员包括 tryEnter。

Singleton no-op implementation.

基于官方固定版本源码静态生成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.