Execution Sandbox Plane (openhusky-sandbox)
openhusky-sandbox implements OpenHusky's Execution Sandbox Plane, decoupling the Control Plane (openhusky-core, openhusky-skills) from filesystem and process execution across five isolation tiers (L0–L4). It relies on standard JDK 21 APIs (ProcessBuilder, Virtual Threads, java.nio.file) with zero docker-java or Netty dependencies.
<dependency>
<groupId>dev.openhusky</groupId>
<artifactId>openhusky-sandbox</artifactId>
<version>0.3.0</version>
</dependency>implementation("dev.openhusky:openhusky-sandbox:0.3.0")Security Isolation Tiers (L0–L4)
| Tier | Implementation | Isolation Mechanism | supportsExec() | Typical Use Case |
|---|---|---|---|---|
| L0 | InMemorySandbox | ConcurrentHashMap<String, byte[]> virtual workspace | false | Fast unit tests, stateless text/artifact generation without disk I/O |
| L1 | LocalHostSandbox | Host directory with toRealPath() jail, atomic temp+move writes, JDK 21 ProcessBuilder | true | Local developer tools and trusted CI runners |
| L2 | LocalOsSandbox | Linux bubblewrap (bwrap with --unshare-net, --ro-bind / /, --die-with-parent) or macOS sandbox-exec (Seatbelt SBPL), FAIL_CLOSED by default | true | Coding agents and untrusted workspace inspection on Linux/macOS hosts |
| L3 | DockerSandbox | Ephemeral container via JDK 21 docker CLI (--cap-drop ALL, --security-opt no-new-privileges, --network none default, memory/CPU/PID limits) | true | Multi-tenant code execution and untrusted build/test workloads |
| L4 | Custom AgentSandbox | Implement dev.openhusky.sandbox.AgentSandbox SPI | Implementation-defined | Cloud micro-VMs & remote sandboxes (Kubernetes Pods, Firecracker, E2B, Modal, Daytona) |
The 6 SandboxToolkit Tools
SandboxToolkit (dev.openhusky.sandbox.SandboxToolkit) exposes up to six AgentTool primitives backed by any AgentSandbox:
| Tool Name | executionMode() | readOnly() | Key Arguments | Safety Defaults & Behavior |
|---|---|---|---|---|
read_file | PARALLEL_SAFE | true | path, offset / start_line, limit | Streaming UTF-8 reader rejecting binary files; 1-based line numbers; 2000 lines / 50 KiB truncation; maxReadBytes = 131_072 (128 KiB). |
glob_files | PARALLEL_SAFE | true | pattern, path (default .), limit / max_results | Skips .git, node_modules, target, build, .idea; sorted by lastModified descending; default limit = 1000. |
grep_files | PARALLEL_SAFE | true | pattern, path, glob, ignore_case, literal, context, limit / max_matches | Streaming regex/literal search over UTF-8 files (skips binaries); default limit = 100. |
write_file | SEQUENTIAL | false | path, content | Atomic write inside sandbox jail; auto-creates parent directories; maxWriteBytes = 1_048_576 (1 MiB). |
edit_file | SEQUENTIAL | false | path, edits[{old_text, new_text}] or old_text + new_text, replace_all | Surgical replacement with BOM/CRLF preservation, fuzzy whitespace fallback, uniqueness check, and unified diff output. |
shell_exec | SEQUENTIAL | false | command, description, cwd, timeout_seconds | Only exposed when sandbox.supportsExec() and enableExec are true; streams throttled progress; defaultExecTimeout = 60s, maxExecTimeout = 300s, tail truncation (50 KiB). |
Use SandboxToolkit.readOnlyTools(sandbox) to expose only read_file, glob_files, and grep_files (ideal for SubagentTool research agents).
Configuration Examples (L1, L2, L3)
Tier L1: Host Directory Sandbox
try (LocalHostSandbox sandbox = LocalHostSandbox.builder(Path.of("/workspace/project"))
.deleteOnClose(false)
.defaultEnv(Map.of("CI", "true"))
.build()) {
List<AgentTool> tools = SandboxToolkit.builder(sandbox)
.defaultExecTimeout(Duration.ofSeconds(30))
.maxExecTimeout(Duration.ofSeconds(120))
.build();
}Tier L2: OS-Level Sandbox (bwrap / Seatbelt, Fail-Closed)
LocalOsSandbox probes bwrap (on Linux) or /usr/bin/sandbox-exec (on macOS) at construction time. Under the default FallbackPolicy.FAIL_CLOSED, calling shell_exec throws SandboxException if OS sandboxing is unavailable rather than silently running unsandboxed on the host:
try (LocalOsSandbox sandbox = LocalOsSandbox.builder(Path.of("/workspace/project"))
.networkAccess(false) // --unshare-net / (deny network*)
.fallbackPolicy(LocalOsSandbox.FallbackPolicy.FAIL_CLOSED)
.extraReadOnlyPaths(List.of(Path.of("/opt/toolchains")))
.build()) {
// Optional: mount read-only skill bundles inside the sandbox workspace
sandbox.mountBundles(".openhusky/skills", skillRegistry.exportAllFiles());
AgentRuntime runtime = AgentRuntime.builder()
.provider(provider)
.model(model)
.tools(SandboxToolkit.tools(sandbox))
.permissionPolicy(PermissionPolicy.failClosed()
.allowReadOnlyTools()
.requireApproval("write_file", "edit_file", "shell_exec")
.build())
.approvalHandler(approvalHandler)
.build();
}Tier L3: Ephemeral Container Sandbox (DockerSandbox)
DockerSandbox starts an ephemeral container lazily on first operation (sleep infinity with --rm --init --cap-drop ALL --security-opt no-new-privileges) and cleans it up via docker rm -f on close():
try (DockerSandbox sandbox = DockerSandbox.builder("eclipse-temurin:21-jdk")
.workspaceDir("/workspace")
.networkAccess(false)
.memoryLimit("512m")
.cpuLimit("1")
.pidsLimit(128)
.readOnlyRootFs(false)
.startupTimeout(Duration.ofSeconds(30))
.build()) {
AgentRuntime runtime = AgentRuntime.builder()
.provider(provider)
.model(model)
.tools(SandboxToolkit.tools(sandbox))
.permissionPolicy(PermissionPolicy.requireApprovalForWrites())
.approvalHandler(approvalHandler)
.build();
}Security Threat Model & Defense-in-Depth
- Path Traversal & Symlink Escape:
SandboxPathsandLocalHostSandboxresolvetoRealPath()on reads, writes, directory listings, andcwdresolution, rejecting..escapes, null bytes, and symlinks pointing outsideworkspaceRoot. - Fail-Closed OS Probe:
LocalOsSandboxdefaults toFallbackPolicy.FAIL_CLOSEDandnetworkAccess = false, ensuring missingbwraporsandbox-execbinaries never degrade silently unlessFallbackPolicy.ALLOW_HOST_FALLBACKis explicitly opted into. - Control-Plane Gating: Combining
LocalOsSandboxorDockerSandboxwithPermissionPolicy.failClosed()andApprovalDecision.Handlergives defense-in-depth—writes and shell commands are gated both by human approval in the Control Plane and by kernel/container isolation in the Execution Plane.