Skip to main content
This guide explains how to run Claude Agent SDK (also known as Claude Code) in Moru sandboxes for building AI-powered development assistants.

What is Claude Agent SDK?

Claude Agent SDK is Anthropic’s official CLI tool for Claude that enables:
  • Interactive AI-assisted coding
  • Tool execution (file operations, shell commands)
  • Extended thinking for complex reasoning
  • Session persistence for long-running tasks

Why Use Moru for Claude Agents?

Running Claude agents in Moru sandboxes provides:

Isolation

Each agent runs in a dedicated microVM, preventing one agent’s actions from affecting others.

Security

Sandboxes limit what agents can access, protecting sensitive systems.

Persistence

Pause and resume sandboxes to maintain agent state across sessions.

Scalability

Spin up sandboxes on demand for concurrent agent sessions.

Architecture

Components

ComponentDescription
Your ApplicationBackend managing sandbox lifecycle
Moru SandboxIsolated environment for the agent
Claude Agent SDKAnthropic’s agent framework
Claude APIAnthropic’s LLM API
WorkspacePersistent filesystem for agent work

Quick Example

Create a sandbox with Claude Agent SDK and run a task:
from moru import Sandbox

# Create a sandbox with Claude Code pre-installed
sandbox = Sandbox.create("claude-code-template", {
    "envs": {
        "ANTHROPIC_API_KEY": "sk-ant-..."
    }
})

# Run an agent task
result = sandbox.commands.run(
    "claude -p 'Create a hello world Python script'",
    timeout=120,
    on_stdout=lambda data: print(data, end="")
)

# Check the created file
content = sandbox.files.read("/home/user/hello.py")
print(content)

sandbox.kill()

Key Concepts

Session Management

Claude Agent SDK maintains session state in JSONL files. This enables:
  • Resuming conversations across sandbox restarts
  • Preserving context between interactions
  • Auditing agent actions

Workspace Persistence

The agent’s workspace (files, configuration) can be:
  • Saved before pausing a sandbox
  • Restored when resuming
  • Synced to external storage

Tool Execution

Claude Agent SDK executes tools within the sandbox:
  • File operations: Read, write, edit files
  • Shell commands: Run any shell command
  • Code execution: Run Python, Node.js, etc.
All within the secure sandbox environment.

Use Cases

Development Assistants

Build AI coding assistants that can:
  • Write and edit code
  • Run tests
  • Debug issues
  • Manage git operations

Data Processing

Create agents that:
  • Transform data files
  • Run analysis scripts
  • Generate reports

Automation

Automate workflows with agents that:
  • Execute multi-step tasks
  • Handle errors gracefully
  • Persist state across runs

Next Steps