@sandagent/sdk — Run Claude in a Sandbox with Vercel AI SDK Streams
Source: Dev.to
Overview
sandagent/sdk is a TypeScript/JavaScript SDK for running Claude agents in a sandboxed environment (local or cloud). It exposes Vercel AI SDK‑compatible streaming, allowing you to:
- Run AI agents in a controlled sandbox without exposing API keys
- Stream messages using the Vercel AI SDK protocol
- Use optional React chat hooks for building UI
- Expose the sandboxed agent as an SDK‑compatible model
npm:
Example: Create a Sandboxed Session & Stream Messages
The following example demonstrates how to create a sandboxed session and stream messages in a way compatible with the Vercel AI SDK. The React chat hooks can be used to integrate real‑time UI components seamlessly.
import { SandAgentClient } from "@sandagent/sdk";
const client = new SandAgentClient({ apiKey: process.env.SANDAGENT_API_KEY });
// Create a sandboxed agent session
const session = await client.createSession("example-session", {
model: "claude-2",
});
// Stream messages
const stream = client.streamMessages(session.id, { prompt: "Hello!" });
for await (const chunk of stream) {
console.log(chunk);
}