Package com.tnsai.quality.sandbox
Interface Sandbox
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
ContainerSandbox,ObservedSandbox,ProcessSandbox,SandboxPool.Lease
A live sandbox instance (TNS-296). Implementations execute untrusted
code through their backend's strongest available boundary (process,
container, microVM, WASM); the consumer interacts through a single
contract regardless of backend. Backend-specific guarantees and
limitations remain part of each implementation's contract.
Lifecycle
SandboxFactory.create(com.tnsai.quality.sandbox.SandboxSpec)returns aSandboxin the started state — the backend has reserved resources but no process is running yet.execute(com.tnsai.quality.sandbox.Command)runs one command to completion (or to theResourceLimits.timeoutbudget). May be called repeatedly inside the same sandbox lifetime — useful for interactive runners and pool-warmed sandboxes.stop()performs a graceful shutdown — the backend sends SIGTERM (or equivalent) and waits a short grace period before terminating.terminate()forcibly kills the sandbox and releases its resources. Idempotent; safe to call from a finally block.
Concurrency
ASandbox is NOT thread-safe — execute must not
be called concurrently on the same instance. Callers needing
concurrency use a SandboxPool.- Since:
- 0.10.0 (TNS-296)
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Runcommandto completion (or until the sandbox kills it for exceedingResourceLimits.timeout).spec()TheSandboxSpecthis instance was created from.voidstop()Graceful shutdown.voidForcibly kill the sandbox and release its resources.
-
Method Details
-
spec
SandboxSpec spec()TheSandboxSpecthis instance was created from. Useful for downstream tooling (audit, observability) that needs to record the configured policy alongside the result. -
execute
Runcommandto completion (or until the sandbox kills it for exceedingResourceLimits.timeout). Always returns aSandboxResult; failures inside the sandbox are reflected inSandboxResult.exitCodeandSandboxResult.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".
- Throws:
SandboxException- when the backend layer can't run the command (terminated sandbox, runtime crash, …)
-
stop
void stop()Graceful shutdown. Backends SHOULD send SIGTERM (or the platform equivalent), wait a short grace period, then promote toterminate()if the process is still running. -
terminate
void terminate()Forcibly kill the sandbox and release its resources. Idempotent — calling on an already-terminated sandbox is a no-op. Safe infinallyblocks. -
close
default void close()- Specified by:
closein interfaceAutoCloseable
-