Class SandboxBackedFilesystem

java.lang.Object
io.agentscope.harness.agent.filesystem.sandbox.BaseSandboxFilesystem
io.agentscope.harness.agent.filesystem.sandbox.SandboxBackedFilesystem
All Implemented Interfaces:
AbstractFilesystem, AbstractSandboxFilesystem, SandboxAware
Direct Known Subclasses:
PinnedSandboxFilesystem

public class SandboxBackedFilesystem extends BaseSandboxFilesystem implements SandboxAware
A BaseSandboxFilesystem that delegates execution to a live Sandbox.

Stable proxy created once per agent bean. The live Sandbox for a call is bound per-call on the invocation's RuntimeContext by SandboxLifecycleMiddleware and resolved here via requireSandbox(RuntimeContext) — this per-call binding takes precedence and is what keeps concurrent distinct-session calls on the same agent bean isolated (issue #2490). The legacy volatile sandbox field is retained only as a best-effort fallback for context-free internal callers that resolve the filesystem with a shared empty RuntimeContext (e.g. WorkspaceMessageBus, which carries no per-call binding). The middleware still maintains that field via setSandbox(io.agentscope.harness.agent.sandbox.Sandbox) on acquire and clearSandboxIfCurrent(io.agentscope.harness.agent.sandbox.Sandbox) on release, so it remains last-writer-wins under concurrency and must not be relied on for isolation.

  • Constructor Details

    • SandboxBackedFilesystem

      public SandboxBackedFilesystem()
  • Method Details

    • setSandbox

      public void setSandbox(Sandbox sandbox)
      Specified by:
      setSandbox in interface SandboxAware
    • getSandbox

      public Sandbox getSandbox()
      Specified by:
      getSandbox in interface SandboxAware
    • clearSandboxIfCurrent

      public void clearSandboxIfCurrent(Sandbox expected)
      Clears the fallback sandbox field only if it still points at expected. Used by SandboxLifecycleMiddleware on release so a finishing call never nulls a concurrent sibling call's fallback binding (issue #2490).
      Parameters:
      expected - the sandbox this call bound at acquire time
    • id

      public String id()
      Description copied from interface: AbstractSandboxFilesystem
      Unique identifier for this filesystem/sandbox instance.
      Specified by:
      id in interface AbstractSandboxFilesystem
      Specified by:
      id in class BaseSandboxFilesystem
      Returns:
      id string
    • execute

      public ExecuteResponse execute(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds)
      Description copied from interface: AbstractSandboxFilesystem
      Execute a shell command in the environment backing this filesystem.
      Specified by:
      execute in interface AbstractSandboxFilesystem
      Specified by:
      execute in class BaseSandboxFilesystem
      Parameters:
      runtimeContext - per-call agent context; may be null when unavailable
      command - full shell command string to execute
      timeoutSeconds - maximum time in seconds to wait for the command to complete; null uses the filesystem's default timeout
      Returns:
      ExecuteResponse with combined output, exit code, and truncation flag; a non-successful response (see ExecuteResponse.isSuccess()) means the command did not complete successfully, so output must not be parsed as normal command output
    • uploadFiles

      public List<FileUploadResponse> uploadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<Map.Entry<String,byte[]>> files)
      Description copied from interface: AbstractFilesystem
      Upload multiple files.
      Specified by:
      uploadFiles in interface AbstractFilesystem
      Specified by:
      uploadFiles in class BaseSandboxFilesystem
      Parameters:
      runtimeContext - per-call agent runtime; RuntimeContext.empty() when none
      files - list of path-to-content mappings to upload
      Returns:
      list of FileUploadResponse objects, one per input file (order matches input order)
    • downloadFiles

      public List<FileDownloadResponse> downloadFiles(io.agentscope.core.agent.RuntimeContext runtimeContext, List<String> paths)
      Description copied from interface: AbstractFilesystem
      Download multiple files.
      Specified by:
      downloadFiles in interface AbstractFilesystem
      Specified by:
      downloadFiles in class BaseSandboxFilesystem
      Parameters:
      runtimeContext - per-call agent runtime; RuntimeContext.empty() when none
      paths - list of file paths to download
      Returns:
      list of FileDownloadResponse objects, one per input path (order matches input order)