Class AbstractBaseSandbox
java.lang.Object
io.agentscope.harness.agent.sandbox.AbstractBaseSandbox
- All Implemented Interfaces:
Sandbox,AutoCloseable
- Direct Known Subclasses:
DockerSandbox
Abstract base implementation of
Sandbox with the 4-branch workspace start logic.
4-Branch Start Logic
Branch A: workspaceRootReady=true & workspace dir exists → apply ephemeral-only entries Branch B: workspaceRootReady=true & workspace dir missing → restore from snapshot + ephemeral entries Branch C: workspaceRootReady=false & snapshot is restorable → hydrate from snapshot + all entries Branch D: workspaceRootReady=false & no restorable snapshot → fresh init from full workspace spec
Subclasses implement the backend-specific operations:
doExec(RuntimeContext, String, int)— execute a shell command in the workspacedoPersistWorkspace()— create a tar archive of the workspacedoHydrateWorkspace(InputStream)— extract a tar archive into the workspacedoSetupWorkspace()— create the workspace root directorydoDestroyWorkspace()— delete the workspace root directory (on shutdown)getWorkspaceRoot()— return the workspace root path string
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected abstract voidDestroys the workspace root and any backend resources.protected abstract ExecResultExecutes a shell command within the workspace.protected abstract voiddoHydrateWorkspace(InputStream archive) Extracts a tar archive into the workspace.protected abstract InputStreamCreates a tar archive of the current workspace contents.protected abstract voidCreates the workspace root directory.exec(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds) Delegates todoExec(RuntimeContext, String, int)with a fallback timeout.protected intReturns the default command execution timeout in seconds.getState()Returns the current serializable state of this sandbox.protected abstract StringReturns the absolute path of the workspace root directory.voidhydrateWorkspace(InputStream archive) booleanprotected booleanProbes whether the workspace root directory still exists, using a backend exec.voidstart()Executes the 4-branch workspace start logic.voidstop()Persists the workspace snapshot and marks the workspace root as ready.
-
Constructor Details
-
AbstractBaseSandbox
-
-
Method Details
-
start
Executes the 4-branch workspace start logic. -
stop
Persists the workspace snapshot and marks the workspace root as ready. -
close
Calls
stop()thenSandbox.shutdown(). Stop failures are logged but do not prevent shutdown.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSandbox- Throws:
Exception
-
isRunning
public boolean isRunning() -
getState
Description copied from interface:SandboxReturns the current serializable state of this sandbox. -
exec
public ExecResult exec(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds) throws Exception Delegates todoExec(RuntimeContext, String, int)with a fallback timeout. -
persistWorkspace
- Specified by:
persistWorkspacein interfaceSandbox- Throws:
Exception
-
hydrateWorkspace
- Specified by:
hydrateWorkspacein interfaceSandbox- Throws:
Exception
-
probeWorkspaceRootForPreservedResume
protected boolean probeWorkspaceRootForPreservedResume()Probes whether the workspace root directory still exists, using a backend exec.Uses
test -d {workspaceRoot}with a 10-second timeout. Returnstrueif the command exits with code 0.- Returns:
- true if the workspace root exists
-
getDefaultExecTimeoutSeconds
protected int getDefaultExecTimeoutSeconds()Returns the default command execution timeout in seconds.- Returns:
- default timeout (120 seconds)
-
doExec
protected abstract ExecResult doExec(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, int timeoutSeconds) throws Exception Executes a shell command within the workspace.- Parameters:
runtimeContext- per-call context; may benullfor internal probescommand- shell command stringtimeoutSeconds- maximum execution time- Returns:
- execution result
- Throws:
Exception- if execution fails
-
doPersistWorkspace
Creates a tar archive of the current workspace contents.- Returns:
- an
InputStreamover the tar stream; caller must close - Throws:
Exception- if archiving fails
-
doHydrateWorkspace
Extracts a tar archive into the workspace.- Parameters:
archive- the tar archive stream to extract- Throws:
Exception- if extraction fails
-
doSetupWorkspace
Creates the workspace root directory.- Throws:
Exception- if directory creation fails
-
doDestroyWorkspace
Destroys the workspace root and any backend resources.- Throws:
Exception- if cleanup fails
-
getWorkspaceRoot
Returns the absolute path of the workspace root directory.- Returns:
- workspace root path string
-