An Agentuity agent that demonstrates Claude Agent SDK integration with Agentuity Sandboxes for conversational code intelligence and safe code execution.
- Code Intelligence — Uses Claude Agent SDK (
@anthropic-ai/claude-agent-sdk) to read, analyze, and generate code in a local workspace seeded with sample TypeScript files. - Sandbox Execution — Runs user code safely in isolated Agentuity Sandboxes (
ctx.sandbox.run()) using the Bun runtime. - Conversation History — Maintains multi-turn conversations via Agentuity thread state, so the agent remembers prior context.
- Chat Frontend — A React-based chat UI for interacting with the agent conversationally.
- Import the project:
agentuity project import - Add
ANTHROPIC_API_KEY=...to.env - Install dependencies:
bun install - Start the dev server:
bun run dev - Open
http://localhost:3500and start chatting about code.
claude-code/
├── src/
│ ├── agent/claude-code/
│ │ ├── index.ts # Agent handler (Claude Agent SDK + Sandbox)
│ │ └── sample-files.ts # Sample TypeScript files for the workspace
│ ├── api/
│ │ └── index.ts # Chat API routes
│ └── web/
│ ├── App.tsx # Chat UI
│ ├── App.css # Tailwind theme
│ ├── frontend.tsx # React entry point
│ └── index.html # HTML template
├── app.ts # Application entry point
├── vite.config.ts # Vite config (React + Tailwind)
└── package.json
- The frontend sends a prompt via
POST /api/chat. - The agent initializes a workspace with sample files and calls Claude Agent SDK's
query(). - Claude Code reads, writes, and analyzes files using built-in tools (Read, Write, Edit, Glob, Grep).
- When the user asks to run code, the agent ships workspace files to an Agentuity Sandbox for execution.
- Results (analysis + execution output) are returned to the chat UI.
The agent calls Claude Agent SDK with permissionMode: 'bypassPermissions' and allowDangerouslySkipPermissions: true. This is intentional for this example:
- Tool scope is narrow. Claude Code is granted only
Read,Write,Edit,Glob, andGrep. There is noBashtool, so it cannot execute arbitrary commands. - Workspace is isolated. Each thread gets its own temporary directory; there is no shared filesystem between sessions.
- Code execution is sandboxed. When the user asks to run code, files are shipped to an Agentuity Sandbox (
ctx.sandbox.run()), not executed on the host.
In a multi-tenant or shared environment, consider restricting cwd to a tighter boundary and auditing which tools are permitted before adopting this pattern.
| Method | Path | Description |
|---|---|---|
| POST | /api/chat |
Send a chat message |
| GET | /api/chat/history |
Get conversation history |
| DELETE | /api/chat/history |
Clear conversation history |
The agent workspace includes these reference files:
fibonacci.ts— Recursive, iterative, and generator Fibonacci implementationsmath-tricks.ts— Prime checking, factorial, GCD, LCM utilitiesclass-example.ts— Animal/Dog/Cat class hierarchy with inheritancehello.ts— Greeting and Fibonacci example
- Bun v1.0+
- Agentuity CLI
ANTHROPIC_API_KEYin local.envfor the Claude Agent SDK
This example calls @anthropic-ai/claude-agent-sdk directly, so ANTHROPIC_API_KEY is the main manual local setup step.
Agentuity services such as dev mode, thread state, and sandboxes use AGENTUITY_SDK_KEY through the normal project setup from agentuity project import.
Minimal local .env:
ANTHROPIC_API_KEY=...