Package com.tnsai.quality.sandbox
Interface SandboxFactory
- All Known Implementing Classes:
ContainerSandboxFactory,ProcessSandboxFactory,WasmSandboxFactory
public interface SandboxFactory
SPI for creating
Sandbox instances (TNS-296). Implementations
are discovered via ServiceLoader; the framework ships
ProcessSandboxFactory as the portable default.
Choosing a backend
Most consumers usepreferred() which auto-selects the
highest-priority factory available on the classpath. Production
deployments can pin a specific backend by passing it directly:
Sandbox sb = SandboxFactory.preferred().create(spec);
SandboxFactory factory = ServiceLoader.load(SandboxFactory.class).stream()
.map(ServiceLoader.Provider::get)
.filter(f -> f.id().equals("container"))
.findFirst().orElseThrow();
- Since:
- 0.10.0 (TNS-296)
-
Method Summary
Modifier and TypeMethodDescriptionbooleantrueif this factory's runtime is reachable on the current host (e.g.static SandboxFactoryFind a factory by itsid()(case-insensitive).create(SandboxSpec spec) Create aSandboxfromspec.id()Stable backend identifier ("process","container","wasm","firecracker", …).static SandboxFactoryintpriority()Higher = preferred.
-
Method Details
-
id
String id()Stable backend identifier ("process","container","wasm","firecracker", …). Used by callers pinning a specific backend. -
priority
int priority()Higher = preferred. The framework's defaultProcessSandboxFactoryreports10; container reports50; firecracker reports100.preferred()picks the highest available. -
available
boolean available()trueif this factory's runtime is reachable on the current host (e.g.ContainerSandboxFactory.available()returnstruewhendockeris on the PATH). Factories that cannot probe cheaply (slow shell-out, network call) should returntrueand surface the failure atcreate(com.tnsai.quality.sandbox.SandboxSpec)time. -
create
Create aSandboxfromspec. Implementations MUST reject specs they cannot honour (e.g. a backend that doesn't supportNetPolicy.AllowListthrows here rather than silently downgrading) — silent relaxation is the accidental-blast-radius footgun this layer exists to prevent.- Throws:
SandboxException- when the backend cannot honour the spec or the runtime is unreachable
-
preferred
The highest-prioritySandboxFactorythat reportsavailable()= true. Falls back to a deterministic process-only factory if no SPI provider is registered (which is the case in stripped-down embedded deployments).- Throws:
SandboxException- if no factory is available
-
byId
Find a factory by itsid()(case-insensitive). Useful for explicit backend selection from configuration.- Throws:
SandboxException- if no factory with that id is registered
-