Class LocalSandboxSnapshot
java.lang.Object
io.agentscope.harness.agent.sandbox.snapshot.LocalSandboxSnapshot
- All Implemented Interfaces:
SandboxSnapshot
Snapshot that persists workspace archives as tar files on the local filesystem.
Archives are written atomically: the data is first written to a temporary file
(prefixed with .) in the same directory, then moved to the final path using
StandardCopyOption.ATOMIC_MOVE. This ensures the snapshot is either fully
written or not present — never partially written.
Security: id must be a single path segment with no / or ..
characters to prevent path traversal attacks.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the base directory where snapshot tar files are stored.getId()Returns the unique identifier for this snapshot.getType()Returns the snapshot type discriminator used in JSON serialization.booleanReturns whether this snapshot can currently be restored.voidpersist(InputStream workspaceArchive) Persists the workspace archive to this snapshot.restore()Restores the workspace archive from this snapshot.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.agentscope.harness.agent.sandbox.snapshot.SandboxSnapshot
isPersistenceEnabled
-
Constructor Details
-
LocalSandboxSnapshot
Creates a local snapshot.- Parameters:
basePath- directory where snapshot tar files are storedid- unique identifier for this snapshot (must be a safe single path segment)- Throws:
IllegalArgumentException- ifidcontains unsafe characters
-
-
Method Details
-
persist
Persists the workspace archive to this snapshot.Writes the archive atomically to
{basePath}/{id}.tar.- Specified by:
persistin interfaceSandboxSnapshot- Parameters:
workspaceArchive- tar stream of the workspace to persist; caller is responsible for closing the stream after this call- Throws:
Exception- if the persist operation fails
-
restore
Restores the workspace archive from this snapshot.Opens the snapshot tar file at
{basePath}/{id}.tarfor reading.- Specified by:
restorein interfaceSandboxSnapshot- Returns:
- tar stream of the workspace; caller is responsible for closing
- Throws:
Exception- if the restore operation fails or the snapshot is not restorable
-
isRestorable
public boolean isRestorable()Returns whether this snapshot can currently be restored.- Specified by:
isRestorablein interfaceSandboxSnapshot- Returns:
trueif the snapshot tar file exists
-
getId
Description copied from interface:SandboxSnapshotReturns the unique identifier for this snapshot.- Specified by:
getIdin interfaceSandboxSnapshot- Returns:
- snapshot id
-
getType
Description copied from interface:SandboxSnapshotReturns the snapshot type discriminator used in JSON serialization.- Specified by:
getTypein interfaceSandboxSnapshot- Returns:
- type string (e.g. "noop", "local", "remote")
-
getBasePath
Returns the base directory where snapshot tar files are stored.- Returns:
- base path string
-