Skip to content

Add Claude Agent SDK in E2B Sandbox example (TypeScript) - #109

Open
ondraulehla wants to merge 1 commit into
e2b-dev:mainfrom
ondraulehla:feat/claude-agent-sdk-in-sandbox
Open

Add Claude Agent SDK in E2B Sandbox example (TypeScript)#109
ondraulehla wants to merge 1 commit into
e2b-dev:mainfrom
ondraulehla:feat/claude-agent-sdk-in-sandbox

Conversation

@ondraulehla

@ondraulehla ondraulehla commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Adds examples/claude-agent-sdk-in-sandbox-js: an agent built with Anthropic's Claude Agent SDK running inside an E2B Sandbox, plus a row in the root README (Anthropic section).

It complements the existing anthropic-claude-code-in-sandbox-js example: instead of piping a prompt into the claude CLI and reading a single stdout blob, the Agent SDK emits structured messages. The example shows the full product-ready loop:

  1. A sandbox template with Node.js 24 and @anthropic-ai/claude-agent-sdk pre-installed (Template SDK, same structure as the Claude Code example).
  2. An in-sandbox script that calls query() and prints each SDK message as a JSON line.
  3. A host script that creates the sandbox, streams and renders the messages (tool calls, text, final result with cost and turn count), and downloads the produced files via the Files API.

Running with permissionMode: "bypassPermissions" is safe in this setup because the sandbox is the security boundary; nothing runs on the user's machine. Authentication works with either ANTHROPIC_API_KEY or a Claude Pro/Max subscription token from claude setup-token (CLAUDE_CODE_OAUTH_TOKEN).

Verification

Template build and end-to-end run against a real sandbox:

Sandbox created ia57h1gnsoxaxtmu2pwb8
Agent started (model: claude-sonnet-5)
> Bash {"command":"pwd","description":"Show current working directory"}
> Write {"file_path":"/agent/workspace/index.html","content":"<!DOCTYPE html>…
Created /agent/workspace/index.html (243 lines, single self-contained file)…

Agent finished: success (4 turns, $0.1316, 33.3s)
Downloaded /agent/workspace/index.html -> output/index.html

The demo prompt has the agent build a self-contained page that trains a small neural network on XOR and animates its decision boundary; the downloaded output/index.html works when opened in a browser.

Runs an agent built with Anthropic's Claude Agent SDK inside an E2B
sandbox: the sandbox template pre-installs the SDK, an in-sandbox script
streams structured agent messages (tool calls, text, final result with
cost) back to the host as JSON lines, and the host downloads the
produced artifacts via the Files API. Complements the existing Claude
Code CLI example with a programmatic, product-ready pattern: full
autonomy via bypassPermissions is safe because the sandbox is the
security boundary.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cla-bot cla-bot Bot added the cla-signed label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant