kosa8 / Best sandboxes

Best sandbox · Claude Agent SDK

The best sandbox for the Claude Agent SDK

Updated

The Claude Agent SDK gives your agent Claude Code's loop and tools, and runs them wherever you host it. The best sandbox for it keeps the commands the agent runs off that host: its own kernel, a network allow-list enforced outside the agent, no API keys inside, and an undo for the whole machine. kosa8 plugs in as an MCP server, so the SDK's agent creates and drives sealed microVMs through tools such as sandbox_create, sandbox_shell and sandbox_rewind, on your own machine or on kosa8 Cloud.

01What a Claude Agent SDK agent needs from a sandbox

An Agent SDK agent writes files, runs shell commands and installs packages with the same built-in tools Claude Code has. By default those act on the machine running your program, so a mistaken rm, a package with a malicious install script or a prompt injection in a fetched page lands on your server.

So the sandbox has to be a place the agent can be given real work: a full Linux userland it can install into, files that persist across a task, long-running processes, and a fast reset when a step goes wrong. It also has to be reachable from the SDK without custom glue, which in practice means MCP, the SDK's built-in way to add tools.

02Checklist for choosing one

  • A boundary that is not the host kernel. A microVM or VM, so a kernel exploit inside does not reach your process.
  • Reachable as MCP tools. The SDK takes stdio and HTTP MCP servers in mcp_servers; anything else means writing your own tools.
  • Network allow-list enforced outside the guest. Root inside the sandbox must not be able to lift it.
  • No long-lived secrets inside. The agent should not be able to read the keys it uses.
  • Checkpoint and rewind of the whole machine. Memory, processes and disk, not only files.
  • Fork. Live copies of a prepared machine, for trying several approaches at once.
  • An audit trail. Every command the agent ran, attributable to that agent.
  • Runs where your data may go. Your laptop, your servers, an air-gapped site or a hosted cloud.

03How kosa8 meets it

Install kosa8 and sign in. kosa8 mcp serve speaks MCP over stdio and exposes kosa8's tools; kosa8 mcp tools lists them.

Then register it in the SDK. The tool names follow the SDK's mcp__<server>__<tool> convention, so mcp__kosa8__* allows them all. Leaving the built-in Bash tool out keeps shell work inside the sandbox.

agent.py
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage
 
async def main():
    options = ClaudeAgentOptions(
        mcp_servers={"kosa8": {"command": "kosa8", "args": ["mcp", "serve"]}},
        allowed_tools=["mcp__kosa8__*"],
        disallowed_tools=["Bash"],
        system_prompt="Do all shell work in a kosa8 sandbox: sandbox_create, then sandbox_shell. "
                      "Take a sandbox_checkpoint before anything you could not undo.",
    )
    async for message in query(prompt="Clone https://github.com/pallets/click into a sandbox "
                                      "and run its tests", options=options):
        if isinstance(message, ResultMessage) and message.subtype == "success":
            print(message.result)
 
asyncio.run(main())

A sandbox the agent creates this way has no network unless it asks for specific hosts, and it can share a host folder only from directories you allowed with kosa8 mcp serve --allow-mount. Every call is in kosa8's hash-chained audit log (kosa8 audit ls).

To run the sandboxes on kosa8 Cloud instead of your machine, point the SDK at the remote MCP server. kosa8 Cloud needs an account with a payment method on file and an API key in KOSA8_API_KEY; see the Cloud quickstart.

cloud.py
import os
from claude_agent_sdk import ClaudeAgentOptions
 
options = ClaudeAgentOptions(
    mcp_servers={"kosa8-cloud": {
        "type": "http",
        "url": "https://api.kosa8.com/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['KOSA8_API_KEY']}"},
    }},
    allowed_tools=["mcp__kosa8-cloud__*"],
)

The cloud server's sandbox_exec stops a command after 30 seconds and keeps /workspace between commands but not background processes, so split long work into shorter steps. The local server has no such limit.

04When another option fits better

  • Claude Code's own sandbox. Claude Code's /sandbox (Seatbelt on macOS, bubblewrap on Linux) restricts file and network access for its Bash tool with nothing extra to install. If your agent only needs that, start there.
  • Anthropic's hosted agents. If you would rather not host the loop or the container at all, Anthropic's Managed Agents run both for you. You give up choosing where the machine runs.
  • A hosted sandbox API you already use. E2B, Daytona and Modal also offer sandboxes reachable from code; if your stack already runs there, stay. kosa8 is the pick when the same sandbox must also run on your own hardware or offline.
  • Plain containers. For trusted code, a Docker container is lighter. It shares the host kernel, which is the point a microVM exists to avoid.

05FAQ

Does the Claude Agent SDK work with kosa8?

Yes, through MCP. Add kosa8 mcp serve as a stdio server in mcp_servers and allow mcp__kosa8__*; the agent then creates, runs in, checkpoints, forks and deletes sandboxes as tools. kosa8 Cloud's server at https://api.kosa8.com/mcp works the same way over HTTP.

Do the SDK's own file tools run inside the sandbox?

No. Built-in tools such as Read, Write and Bash act on the machine running your program. Keep shell work in the sandbox by leaving Bash out and telling the agent to use sandbox_shell; use sandbox_file_read and sandbox_file_write for files inside it.

Can the agent undo its own mistakes?

Yes. sandbox_checkpoint saves memory, processes and disk, and sandbox_rewind puts the machine back with processes resumed. kosa8 keeps the last 10 checkpoints per sandbox.

Where do the sandboxes run?

With kosa8 mcp serve, on the machine running the kosa8 daemon: an Apple silicon Mac, x86-64 Linux, or Windows through WSL2. With the cloud server, on kosa8 Cloud in the US or the EU.

06Get started

Install kosa8 on a Mac, Linux or Windows (WSL2) machine, or make an account and run the same sandboxes on kosa8 Cloud.

07Sources

Related

Updated 2026-11-14