Skip to main content

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.

Workspace roots do not isolate processes

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.

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())

Hardware isolation​

  • LocalSandbox / Sandbox: Canonicalizes paths against root_dir to block .. traversal and exposes read, write, edit, delete, list, glob, grep, and bounded process helpers (ProcessLimits defaults 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 deterministic fuel_limit instruction budgets. If the caller omits a profile, Rust defaults required_isolation to runtime; SDKs do not inject this policy themselves.
  • PermissionsManager: Enforces glob-based allow / deny rules 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:

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())

3. Declarative Permission Rules (PermissionsManager)​

Guard sensitive paths with glob-based allow/deny rules (PermissionRule / PermissionsManager.Rule):

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"))

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.