Interface Sandbox
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
AbstractBaseSandbox,DockerSandbox
An active sandbox with a fully isolated workspace.
Lifecycle:
- Acquire via
SandboxClient.create(io.agentscope.harness.agent.sandbox.WorkspaceSpec, io.agentscope.harness.agent.sandbox.snapshot.SandboxSnapshotSpec, O)(new) orSandboxClient.resume(io.agentscope.harness.agent.sandbox.SandboxState)(existing) - Call
start()— initializes or restores the workspace - Use
exec(io.agentscope.core.agent.RuntimeContext, java.lang.String, java.lang.Integer)for command execution,persistWorkspace()/hydrateWorkspace(java.io.InputStream)for archive operations - Call
stop()— persists the snapshot (does NOT destroy resources) - Call
shutdown()— destroys backend resources (tmpdir, container) - Or use
close()which calls stop + shutdown in sequence
The distinction between stop() and shutdown() is critical:
stop(): persist snapshot only — safe for both self-managed and user-managed sandboxesshutdown(): destroy backend resources — only called on self-managed sandboxes
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()exec(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds) Runs a shell command in the sandbox workspace.getState()Returns the current serializable state of this sandbox.voidhydrateWorkspace(InputStream archive) booleandefault voidshutdown()voidstart()voidstop()
-
Method Details
-
start
- Throws:
Exception
-
stop
- Throws:
Exception
-
shutdown
- Throws:
Exception
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
isRunning
boolean isRunning() -
getState
SandboxState getState()Returns the current serializable state of this sandbox.- Returns:
- state (may be modified by lifecycle methods)
-
exec
ExecResult exec(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds) throws Exception Runs a shell command in the sandbox workspace.- Parameters:
runtimeContext- per-call agent context (session, user, attributes); may benullcommand- shell commandtimeoutSeconds- max wait;nullfor implementation default- Throws:
Exception
-
persistWorkspace
- Throws:
Exception
-
hydrateWorkspace
- Throws:
Exception
-