Sandboxes
Choose the execution boundary that matches the work: workspace file tools for
reading and editing project files, an OS sandbox for shell commands, or WASI for
untrusted WebAssembly modules. PermissionsManager separately controls which
paths and operations are allowed.
The per-language LocalSandbox, KernelSandbox, and Sandbox classes are
wrappers over shared Rust filesystem and process operations. They expose familiar
constructors and result types; they do not implement separate sandbox engines.
The workspace root confines ISH's filesystem tools. It does not restrict an arbitrary shell command or other code running in your process. Use the kernel isolation helpers for commands that need an OS boundary, and keep exposed tools and permission rules scoped to the task.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import KernelSandbox, assess_sandbox_profile, run_wasi_module
async def main() -> None:
assessment = assess_sandbox_profile(
profile={"read_roots": ["./workspace"], "write_roots": [], "required_isolation": "runtime"},
capabilities={"os_sandbox_available": True, "wasm_available": True},
)
print("Assessment:", assessment)
sandbox = KernelSandbox(root_dir="./workspace", network=False)
output = await sandbox.execute("ls -la", timeout=5.0)
print(output)
# Execute a compiled WASI Preview 1 module (WAT or .wasm bytes). When no
# profile is supplied, Rust requires runtime isolation by default:
wat_module = b'(module (func (export "_start")))'
wasi = run_wasi_module(wat_module, fuel_limit=100_000)
print("WASI exit code:", wasi["exit_code"])
asyncio.run(main())
import { IshClient, Sandbox } from "ish-harness";
const client = new IshClient();
const sandbox = new Sandbox(client, "./workspace");
try {
const assessment = sandbox.assessProfile(
{ read_roots: ["./workspace"], write_roots: [], required_isolation: "runtime" },
{ os_sandbox_available: true, wasm_available: true },
);
console.log("Assessment:", assessment);
const proc = sandbox.executeKernelProcess("ls -la", {
timeoutMs: 5000,
network: false,
});
console.log(proc.stdout);
const wat = Buffer.from('(module (func (export "_start")))');
const wasi = sandbox.runWasiModule(wat, { fuelLimit: 100_000 });
console.log("WASI exit code:", wasi.exit_code);
} finally {
sandbox.close();
client.close();
}
use std::{env, sync::Arc};
use ish_harness::{Agent, OpenAIModel};
use ish_harness::sandbox::LocalSandbox;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let sandbox = LocalSandbox::new("./workspace");
let model = OpenAIModel::new(
"gpt-4o-mini".into(),
"https://api.openai.com/v1".into(),
env::var("OPENAI_API_KEY")?,
0.0,
);
let agent = Agent::builder(Arc::new(model))
.name("coder")
.instructions("Use the workspace tools to inspect the requested files.")
.sandbox(&sandbox)
.build()?;
let result = agent.run("Read notes/todo.txt and summarize it.").await?;
println!("{}", result.content);
Ok(())
}
package main
import (
"fmt"
"time"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
sandbox, err := ish.NewSandbox(client, "./workspace")
if err != nil {
panic(err)
}
defer sandbox.Close()
assessment, err := sandbox.AssessProfile(
map[string]any{"read_roots": []string{"./workspace"}, "write_roots": []string{}, "required_isolation": "runtime"},
map[string]any{"os_sandbox_available": true, "wasm_available": true},
)
if err != nil {
panic(err)
}
fmt.Println("Assessment:", assessment)
execRes, err := sandbox.ExecuteKernelProcess(
"ls -la",
5*time.Second,
ish.Uint64Ptr(15),
ish.Uint64Ptr(512*1024*1024),
false,
false,
)
if err != nil {
panic(err)
}
fmt.Println(execRes.Stdout)
wasi, err := sandbox.RunWasiModule([]byte(`(module (func (export "_start")))`), nil, nil, nil, nil, ish.Uint64Ptr(100_000))
if err != nil {
panic(err)
}
fmt.Println("WASI exit code:", wasi.ExitCode)
}
using System;
using System.Text;
using System.Text.Json;
using Ish.Harness;
using var client = new IshClient();
using var sandbox = new Sandbox(client, "./workspace");
var profile = JsonDocument.Parse("""{"read_roots":["./workspace"],"write_roots":[],"required_isolation":"runtime"}""").RootElement;
var caps = JsonDocument.Parse("""{"os_sandbox_available":true,"wasm_available":true}""").RootElement;
Console.WriteLine("Assessment: " + sandbox.AssessProfile(profile, caps));
var exec = sandbox.ExecuteKernelProcess("ls -la", TimeSpan.FromSeconds(5), network: false);
Console.WriteLine(exec.Stdout);
var wasmBytes = Encoding.UTF8.GetBytes("(module (func (export \"_start\")))");
var wasi = sandbox.RunWasiModule(wasmBytes, fuelLimit: 100_000);
Console.WriteLine($"WASI exit code: {wasi.ExitCode}");
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.ishharness.IshClient;
import io.github.ishharness.Sandbox;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
public class KernelAndWasiExample {
public static void main(String[] args) throws Exception {
var mapper = new ObjectMapper();
var profile = mapper.readTree("{\"read_roots\":[\"./workspace\"],\"write_roots\":[],\"required_isolation\":\"runtime\"}");
var caps = mapper.readTree("{\"os_sandbox_available\":true,\"wasm_available\":true}");
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var sandbox = new Sandbox(client, "./workspace")) {
System.out.println("Assessment: " + sandbox.assessProfile(profile, caps));
var exec = sandbox.executeKernelProcess("ls -la", 5000L, 15L, 512L * 1024 * 1024, false);
System.out.println(exec.stdout());
byte[] wat = "(module (func (export \"_start\")))".getBytes(StandardCharsets.UTF_8);
var wasi = sandbox.runWasiModule(wat, null, null, null, null, 100_000L);
System.out.println("WASI exit code: " + wasi.exitCode());
}
}
}
Hardware isolation
LocalSandbox/Sandbox: Canonicalizes paths againstroot_dirto block..traversal and exposes read, write, edit, delete, list, glob, grep, and bounded process helpers (ProcessLimitsdefaults to 15 CPU seconds and 512 MiB unless overridden).- Kernel Isolation (
KernelSandbox/executeKernelProcess): Executes commands inside macOS Seatbelt (sandbox-exec) or Linux Bubblewrap (bwrap) when available on the host, and fails closed (refuses execution) if no kernel isolation backend is detected. - WASI Execution (
runWasiModule/execute_wasm): Runs WASI Preview 1 modules inside Wasmtime with capability profiles (assessProfile/assess_sandbox_profile) and deterministicfuel_limitinstruction budgets. If the caller omits a profile, Rust defaultsrequired_isolationtoruntime; SDKs do not inject this policy themselves. PermissionsManager: Enforces glob-basedallow/denyrules across filesystem operations (read,write,delete,list) and file tools before execution.
1. Kernel isolation, WASI execution
Evaluate sandbox capability profiles, run commands under OS kernel isolation, or run WASI modules with deterministic fuel budgets:
An isolated process API call does not automatically add an isolated shell tool to
an agent. If a skill needs to run a bundled script, the application must expose a
tool that invokes KernelSandbox.execute or executeKernelProcess and ensure the
skill files are inside the sandbox root. Sandbox.agentTools() exposes the
standard workspace tool catalog; its execute command is workspace-rooted but
does not provide an OS isolation boundary.
2. Local Workspace Sandbox (LocalSandbox / Sandbox)
Use LocalSandbox (Python/Rust) or Sandbox (TypeScript/Go/C#/Java) to keep file reads, writes, edits, globs, and searches pinned inside a workspace directory and expose the shared filesystem tool catalog to agents. Python's filesystem_tools and the four host SDKs' Sandbox.agentTools() adapters use the same Rust-defined descriptors and sandbox operations. Rust can mount native tool backends with AgentBuilder::sandbox; AgentBuilder::sandbox_with_eval also mounts the restricted deterministic expression evaluator:
- Python
- TypeScript
- Rust
- Go
- C#
- Java
import asyncio
from ish import Agent, LocalSandbox, OpenAICompatibleModel, filesystem_tools
async def main() -> None:
sandbox = LocalSandbox(root_dir="./workspace")
await sandbox.write_file("notes/todo.txt", "Add tests for sandbox.\n")
content = await sandbox.read_file("notes/todo.txt", offset=1, limit=50)
print(content)
agent = Agent(
name="coder",
model=OpenAICompatibleModel(model="gpt-4o-mini"),
tools=filesystem_tools(root_dir="./workspace"),
)
result = await agent.run("Read notes/todo.txt and summarize it.")
print(result.content)
asyncio.run(main())
import { Agent, IshClient, Sandbox } from "ish-harness";
const client = new IshClient();
const sandbox = new Sandbox(client, "./workspace");
try {
sandbox.writeFile("notes/todo.txt", "Add tests for sandbox.\n");
console.log(sandbox.readFile("notes/todo.txt", 1, 50));
const agent = new Agent({
name: "coder",
model: { provider: "openai_chat", name: "gpt-4o-mini" },
tools: sandbox.agentTools(),
max_turns: 4,
});
const result = await agent.run("Read notes/todo.txt and summarize it.");
console.log(result.content);
} finally {
sandbox.close();
client.close();
}
use ish_harness::sandbox::LocalSandbox;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let sandbox = LocalSandbox::new("./workspace");
sandbox.write_file("notes/todo.txt", "Add tests for sandbox.\n")?;
sandbox.edit_file("notes/todo.txt", "Add tests", "Write integration tests")?;
let content = sandbox.read_file("notes/todo.txt", 1, 50)?;
println!("{content}");
Ok(())
}
package main
import (
"context"
"fmt"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
sandbox, err := ish.NewSandbox(client, "./workspace")
if err != nil {
panic(err)
}
defer sandbox.Close()
_, _ = sandbox.WriteFile("notes/todo.txt", "Add tests for sandbox.\n")
text, _ := sandbox.ReadFile("notes/todo.txt", ish.IntPtr(1), ish.IntPtr(50))
fmt.Println(text)
tools, _ := sandbox.AgentTools()
agent := ish.NewAgent(client, ish.AgentRunRequest{
Model: &ish.AgentModel{Provider: "openai_chat", Name: "gpt-4o-mini"},
Tools: tools,
MaxTurns: ish.IntPtr(4),
})
res, err := agent.Run(context.Background(), "Read notes/todo.txt and summarize it.")
if err != nil {
panic(err)
}
fmt.Println(res["content"])
}
using System;
using Ish.Harness;
using var client = new IshClient();
using var sandbox = new Sandbox(client, "./workspace");
sandbox.WriteFile("notes/todo.txt", "Add tests for sandbox.\n");
Console.WriteLine(sandbox.ReadFile("notes/todo.txt", 1, 50));
var result = client.Run(new AgentRunRequest
{
Model = new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
UserPrompt = "Read notes/todo.txt and summarize it.",
Tools = sandbox.AgentTools(),
MaxTurns = 4
});
Console.WriteLine(result.GetProperty("content").GetString());
import com.fasterxml.jackson.databind.JsonNode;
import io.github.ishharness.IshClient;
import io.github.ishharness.Sandbox;
import java.nio.file.Path;
public class WorkspaceSandboxExample {
public static void main(String[] args) {
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var sandbox = new Sandbox(client, "./workspace")) {
sandbox.writeFile("notes/todo.txt", "Add tests for sandbox.\n");
System.out.println(sandbox.readFile("notes/todo.txt", 1, 50));
var request =
new IshClient.AgentRequest("gpt-4o-mini", "Use workspace tools.", "Read notes/todo.txt and summarize it.")
.provider("openai_chat")
.maxTurns(4);
for (JsonNode tool : sandbox.agentTools()) {
request.operationTool(tool);
}
JsonNode result = client.runAgent(request);
System.out.println(result.path("content").asText());
}
}
}
3. Declarative Permission Rules (PermissionsManager)
Guard sensitive paths with glob-based allow/deny rules (PermissionRule / PermissionsManager.Rule):
- Python
- TypeScript
- Rust
- Go
- C#
- Java
from ish import PermissionRule, PermissionsManager
permissions = PermissionsManager(
rules=[
PermissionRule(paths=["secrets/**", "*.env"], operations=["read", "write"], mode="deny"),
PermissionRule(paths=["src/**"], operations=["read"], mode="allow"),
],
default_mode="allow",
)
print("Read secrets/prod.env allowed:", permissions.check("read", "secrets/prod.env"))
print("Tool check:", permissions.explain_tool("read_file", "secrets/prod.env"))
import { IshClient, PermissionsManager } from "ish-harness";
const client = new IshClient();
const permissions = new PermissionsManager(
client,
[
{ paths: ["secrets/**", "*.env"], operations: ["read", "write"], mode: "deny" },
{ paths: ["src/**"], operations: ["read"], mode: "allow" },
],
"allow",
);
try {
console.log("Allowed:", permissions.check("read", "secrets/prod.env"));
console.log("Explain:", permissions.explain("read", "secrets/prod.env"));
} finally {
permissions.close();
client.close();
}
use ish_harness::{PermissionRule, PermissionsManager};
fn main() {
let permissions = PermissionsManager::new(
vec![
PermissionRule {
paths: vec!["secrets/**".into(), "*.env".into()],
operations: vec!["read".into(), "write".into()],
mode: "deny".into(),
},
PermissionRule {
paths: vec!["src/**".into()],
operations: vec!["read".into()],
mode: "allow".into(),
},
],
"allow",
);
println!("Allowed: {}", permissions.check("read", "secrets/prod.env"));
println!("Decision: {:?}", permissions.explain("read", "secrets/prod.env"));
}
package main
import (
"fmt"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
permissions, err := ish.NewPermissionsManager(
client,
[]ish.PermissionRule{
{Paths: []string{"secrets/**", "*.env"}, Operations: []string{"read", "write"}, Mode: "deny"},
{Paths: []string{"src/**"}, Operations: []string{"read"}, Mode: "allow"},
},
"allow",
)
if err != nil {
panic(err)
}
defer permissions.Close()
allowed, _ := permissions.Check("read", "secrets/prod.env")
fmt.Println("Allowed:", allowed)
}
using System;
using Ish.Harness;
using var client = new IshClient();
using var permissions = new PermissionsManager(
client,
[
new PermissionRule(["secrets/**", "*.env"], ["read", "write"], "deny"),
new PermissionRule(["src/**"], ["read"], "allow")
],
defaultMode: "allow");
Console.WriteLine("Allowed: " + permissions.Check("read", "secrets/prod.env"));
Console.WriteLine("Explain: " + permissions.Explain("read", "secrets/prod.env"));
import io.github.ishharness.IshClient;
import io.github.ishharness.PermissionsManager;
import java.nio.file.Path;
import java.util.List;
public class PermissionsExample {
public static void main(String[] args) {
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")));
var permissions =
new PermissionsManager(
client,
List.of(
new PermissionsManager.Rule(
List.of("secrets/**", "*.env"), List.of("read", "write"), "deny"),
new PermissionsManager.Rule(List.of("src/**"), List.of("read"), "allow")),
"allow")) {
System.out.println("Allowed: " + permissions.check("read", "secrets/prod.env"));
System.out.println("Explain: " + permissions.explain("read", "secrets/prod.env"));
}
}
}
Shared deterministic expression evaluation
eval_code is backed by Rust's sandbox.eval_expression operation and is exposed across SDKs. It evaluates a restricted deterministic expression subset for math, JSON, and collection transformations. It is separate from the filesystem and process sandbox and does not execute arbitrary Python.