SandboxExecutionGuard
@FunctionalInterface public interface SandboxExecutionGuard
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | SandboxIsolationKey | 键(类型 `SandboxIsolationKey`)。the isolation key that identifies the sandbox slot to protect |
SandboxLeaseInterruptedException可能抛出 `InterruptedException`。Thrown when the operation cannot be completed.
io/agentscope/harness/agent/sandbox/SandboxExecutionGuard.java:72noop
static public SandboxExecutionGuard noop()
返回 noop 结果。
Returns the default no-op guard: execution is always allowed immediately and the returned SandboxLease is a no-op.
SandboxExecutionGuardio/agentscope/harness/agent/sandbox/SandboxExecutionGuard.java:78–80嵌套类详情Nested Class Detail
NoopSandboxExecutionGuard
final class NoopSandboxExecutionGuard implements SandboxExecutionGuardNoop 沙箱执行守卫,承载智能体的部署、调度与服务化运行。位于 io.agentscope.harness.agent.sandbox 包,实现 SandboxExecutionGuard。核心成员包括 tryEnter。
Singleton no-op implementation.