Class LocalSandboxSnapshot

java.lang.Object
io.agentscope.harness.agent.sandbox.snapshot.LocalSandboxSnapshot
All Implemented Interfaces:
SandboxSnapshot

public class LocalSandboxSnapshot extends Object implements 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 Details

    • LocalSandboxSnapshot

      public LocalSandboxSnapshot(String basePath, String id)
      Creates a local snapshot.
      Parameters:
      basePath - directory where snapshot tar files are stored
      id - unique identifier for this snapshot (must be a safe single path segment)
      Throws:
      IllegalArgumentException - if id contains unsafe characters
  • Method Details

    • persist

      public void persist(InputStream workspaceArchive) throws Exception
      Persists the workspace archive to this snapshot.

      Writes the archive atomically to {basePath}/{id}.tar.

      Specified by:
      persist in interface SandboxSnapshot
      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

      public InputStream restore() throws Exception
      Restores the workspace archive from this snapshot.

      Opens the snapshot tar file at {basePath}/{id}.tar for reading.

      Specified by:
      restore in interface SandboxSnapshot
      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:
      isRestorable in interface SandboxSnapshot
      Returns:
      true if the snapshot tar file exists
    • getId

      public String getId()
      Description copied from interface: SandboxSnapshot
      Returns the unique identifier for this snapshot.
      Specified by:
      getId in interface SandboxSnapshot
      Returns:
      snapshot id
    • getType

      public String getType()
      Description copied from interface: SandboxSnapshot
      Returns the snapshot type discriminator used in JSON serialization.
      Specified by:
      getType in interface SandboxSnapshot
      Returns:
      type string (e.g. "noop", "local", "remote")
    • getBasePath

      public String getBasePath()
      Returns the base directory where snapshot tar files are stored.
      Returns:
      base path string