Sandstorm Documentation

repository·main·Indexed 19 days ago

https://github.com/tomascupr/sandstorm

An open-source, self-hostable runtime for general-purpose AI agents in isolated sandboxes. Sandstorm supports multi-provider LLMs, Slack integration, and OpenTelemetry observability. It includes a TypeScript client for streaming agent responses via SSE and provides examples for structured workflows such as automated code reviews and competitive market analysis.

Tokens
43.7K
Snippets
142
Records
213
Agent score
65%

What's inside Sandstorm

  1. Understand the Sandstorm runtime model

    main

    Every request follows a specific lifecycle:

    1. Sandbox Creation: Sandstorm creates a fresh sandbox using the configured runtime (E2B by default).
    2. Upload: Your configuration, prompt, and any specified files are uploaded to the sandbox.
    3. Execution: The Claude Agent SDK runs inside the sandbox using the configured tools.
    4. Streaming: Sandstorm streams events back to the user via CLI, API, or Slack.
    5. Cleanup: The sandbox is destroyed once the task is finished.
  2. Define sub-agents for task delegation

    main

    You can define specialist sub-agents in the agents object. The main agent can delegate work to these specialists using the Task tool.

    Important: Sub-agents are for internal delegation. For external tool integrations, use mcp_servers instead.

    {
      "agents": {
        "scraper": {
          "description": "Crawls websites and saves structured data to disk.",
          "prompt": "Scrape the target, extract the useful data, and save it to /home/user/output/.",
          "tools": ["Bash", "WebFetch", "Write", "Read"],
          "model": "sonnet"
        }
      }
    }
  3. Understand the Security Auditor architecture

    main

    The Security Auditor uses a multi-agent architecture where a main agent (team lead) coordinates specialized sub-agents to cover different attack surfaces. The main agent uses the Task tool to spawn these sub-agents, collects their findings, deduplicates them, and synthesizes the final report.

    Agent Hierarchy:

    • Main Agent (team lead, sonnet): Coordinates sub-agents and synthesizes findings.
    • dependency-scanner (sonnet): Performs pip audit, npm audit, and CVE checks.
    • code-scanner (sonnet): Performs OWASP Top 10 static analysis.
    • config-scanner (haiku): Performs configuration reviews.
  4. Scale Sandstorm horizontally

    main

    Since Sandstorm's core query execution is stateless, you can scale horizontally by running multiple Sandstorm instances behind a load balancer.

    Scaling Considerations:

    • Compute Bottleneck: When using the default E2B runtime, the primary bottleneck is your E2B plan limits (concurrent sandbox limits), not the Sandstorm server itself.
    • Server Resources: A single 2-core machine can typically handle dozens of concurrent agents as the server mainly manages open SSE connections and streams stdout.
  5. Compare Sandstorm with Local-Daemon Slack Bots

    main

    Many community projects (like claude-code-slack-bot) run Claude Code on a local machine or a single dedicated daemon. Sandstorm is designed for production team environments.

    Key differences:

    • Isolation: Sandstorm runs a fresh sandbox (e.g., E2B) per thread, whereas local bots run on the host machine's environment.
    • Security: Sandstorm limits the 'blast radius' of bad prompts by using sandboxes that can be torn down or paused.
    • Concurrency: Sandstorm supports multi-user concurrency via a per-thread sandbox pool, while local bots are typically serialized through a single process.
    • Deployment: Sandstorm is built for production deployment (Docker, Railway, etc.), whereas local bots require a machine to stay online.
  6. Compare Managed Agents and Sandstorm

    main

    Decide between Anthropic Managed Agents (MA) and Sandstorm based on your orchestration and infrastructure requirements.

    Choose Managed Agents if:

    • You want a Claude-only, Anthropic-hosted, zero-infrastructure experience.
    • You do not require multi-provider routing.
    • You are comfortable with per-session-hour billing.
    • You prefer to build and maintain your own scheduler and Slack bot.

    Choose Sandstorm if:

    • You need self-hosted, multi-provider (OpenRouter, Vertex, Bedrock, etc.), or data-residency control.
    • You want a production-ready Slack bot (mentions, DMs, slash commands) out of the box.
    • You need sub-hourly scheduling (Sandstorm supports minute-level * * * * * cron, whereas Claude Code Routines is limited to 1-hour minimums).
    • You want full ownership of your observability (e.g., OpenTelemetry).
  7. Use advanced Sandstorm patterns

    main

    Advanced patterns are specialized workflows that use specific features like output_format, allowed_tools, WebFetch, or multi-agent configurations. Use these when you need a tighter, more structured workflow than the standard starters.

    Available Advanced Patterns

    • Competitive Analysis: Research competitors using a market-analysis schema. Uses output_format, WebFetch, and WebSearch.
    • Content Brief: Generate search-driven content briefs. Uses output_format and WebSearch.
    • Issue Triage: Triage uploaded issue exports using a strict engineering rubric. Uses output_format, allowed_tools, and file uploads.
    • Code Reviewer: Produce structured reports with severity and fixes. Uses output_format, allowed_tools, and file uploads.
    • Repo Migration: Plan staged migrations without write access. Uses output_format, allowed_tools, and file uploads.
    • Docs to OpenAPI: Crawl documentation to generate draft OpenAPI specs. Uses output_format, WebFetch, and Write.
    • Security Auditor: Run multi-agent audits with baked-in OWASP skills. Uses agents, skills_dir, and allowed_tools.
  8. Security considerations for custom MCP servers

    main

    Custom MCP servers run inside your configured sandbox runtime. A malicious or buggy package has the same access to the sandbox as the agent, including:

    • Filesystem access
    • Network access (subject to runtime policies)
    • Any environment variables passed via --env

    Best Practices:

    1. Prefer well-known first-party MCPs (e.g., HubSpot, Notion, Linear).
    2. For community packages, audit the source code before adding them.
    3. Use allowed_tools to scope the agent's capabilities, limiting it to only the specific tools required rather than the full MCP surface.
  9. Understand memory scopes

    main

    Memories are organized into three hierarchical scopes. The agent sees all three concatenated in the system prompt, starting with the most general scope first:

    1. team: Shared across everyone in the Slack tenant (the workspace, or enterprise for Grid installs).
    2. channel: Shared across users in a specific Slack channel.
    3. user: Personal to one user in one tenant (the default scope since v0.9.0).

    Isolation: Memories are keyed on (team_id, user_id). There is no cross-workspace sharing. A user in Workspace A cannot access memories from Workspace B. For CLI/HTTP runs without Slack context, both keys default to __local__.

  10. Compare Sandstorm with Vercel Slack Agent Skill

    main

    Sandstorm and Vercel's Slack Agent Skill represent different architectural approaches to Slack-based agents.

    Use Sandstorm if you need:

    • Python Stack: Built with FastAPI.
    • Infrastructure Independence: Deploy anywhere that runs Python, not just Vercel.
    • Built-in Replay: Use ds replay <run_id> to replay and archive runs.
    • First-class Memory: Managed memory using JSONL per (team_id, user_id).
    • Open Observability: OTel support for any backend.

    Use Vercel Slack Agent Skill if: You are already in the Vercel ecosystem, your team uses TypeScript, and you want managed durable execution via Workflow DevKit.

  11. Content Brief Generator Configuration and Features

    main

    The Content Brief Generator uses specific configuration settings to produce structured, research-backed outputs. Key features include:

    • output_format: Uses a JSON schema containing title options, keywords, an outline, and competitor gaps.
    • max_turns: Set to 15 to allow the agent sufficient steps to perform web research, analyze competitors, and synthesize findings.
    • system_prompt: Employs a 'Content strategist' persona to research ranking content and identify gaps.
    • WebSearch: Enabled by default to research existing content, keywords, and competitor angles.
    • model: Typically uses sonnet for a balance of research quality and speed.
  12. Sandstorm Slack Bot Features

    main

    The Slack integration includes several advanced features for agent interaction:

    • Streaming responses: Agent output appears in real-time.
    • File uploads: Supports text (code, CSV, JSON, logs) and binary (images, PDFs, audio, video, zip) up to 10 MB per file.
    • Sandbox reuse per thread: Follow-up mentions in the same thread reuse the same sandbox, maintaining state and file access.
    • File extraction: Agent-created files are automatically uploaded to the Slack thread (up to 10 files, 25 MB per file, 50 MB total).
    • Feedback buttons: Thumbs up/down buttons on responses to record feedback in the run store.
    • Metadata footer: Displays model, turns, cost, and duration for every response.
    • App Home: A dedicated tab in the bot's DM to view run status, cancel in-flight runs, view memories, and see channel defaults.
    • Slash Commands:
      • /cancel: Stops the most recent running agent in the current channel.
      • /remember, /team-remember, /channel-remember: Manage different levels of memory.
    • Reaction-triggered runs: Use emoji reactions to fire an agent with the reacted message as context.