Class SandboxPool.Lease

java.lang.Object
com.tnsai.quality.sandbox.SandboxPool.Lease
All Implemented Interfaces:
Sandbox, AutoCloseable
Enclosing class:
SandboxPool

public static final class SandboxPool.Lease extends Object implements Sandbox
Lease wrapping a borrowed sandbox. close() returns the sandbox to the pool. Implements Sandbox so callers can use the lease directly in code paths that expect a Sandbox.
  • Method Details

    • spec

      public SandboxSpec spec()
      Description copied from interface: Sandbox
      The SandboxSpec this instance was created from. Useful for downstream tooling (audit, observability) that needs to record the configured policy alongside the result.
      Specified by:
      spec in interface Sandbox
    • execute

      public SandboxResult execute(Command command)
      Description copied from interface: Sandbox
      Run command to completion (or until the sandbox kills it for exceeding ResourceLimits.timeout). Always returns a SandboxResult; failures inside the sandbox are reflected in SandboxResult.exitCode and SandboxResult.stderr, not thrown.

      Throws if the sandbox itself has been terminated, or if the backend layer cannot dispatch the command (image missing, runtime crash). Those are infrastructure failures, distinct from "the user's command exited non-zero".

      Specified by:
      execute in interface Sandbox
    • stop

      public void stop()
      Description copied from interface: Sandbox
      Graceful shutdown. Backends SHOULD send SIGTERM (or the platform equivalent), wait a short grace period, then promote to Sandbox.terminate() if the process is still running.
      Specified by:
      stop in interface Sandbox
    • terminate

      public void terminate()
      Terminates the underlying sandbox and removes it from the pool — use close() to return it for reuse.
      Specified by:
      terminate in interface Sandbox
    • close

      public void close()
      Returns the sandbox to the pool. Idempotent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Sandbox