English Arabic 简体中文 繁體中文 Français Deutsch 日本語 한국어 Português Русский Español

How to Deploy and Host Claude Agent SDK with Novita Sandbox

How to Deploy and Host Claude Agent SDK with Novita Sandbox

In 2026, the AI landscape has reached a definitive turning point: the transition from experimental intelligence to industrialized execution. While the first wave of AI focused on conversation, the current era is defined by agency.

With the release of the Claude Agent SDK, the paradigm has shifted from stateless APIs to stateful, persistent runtimes. Developers are no longer satisfied with agents that merely generate code—they demand systems that can execute, debug, and iterate autonomously. Unlike traditional LLMs that “forget” after every request, Claude Agent SDK now maintain a continuous reasoning loop, writing code, debugging in real-time, and managing complex file systems.

However, a critical gap remains: infrastructure. To move from demo to production-grade digital workforce, agents require more than intelligence—they need secure, scalable, high-performance, and affordable environments to perform their work.

Learn how to deploy and host Claude agents in production using Novita Sandbox, an E2B-compatible cloud execution environment that bridges this gap with cost-effective, enterprise-grade infrastructure.

💡 Ready to Start Building?
Novita provides a complete, production-ready Claude Agent SDK example with interactive CLI, tool implementations, and best practices. Clone the repository and run your first agent in minutes.

Core Advantages: Built for Anthropic

1. True “Zero Refactoring” Migration

Novita provides a fully compatible Anthropic API endpoint. Simply change one baseURL to give your existing Claude-powered applications real-world execution capabilities.

  • Native Integration: Use @anthropic-ai/sdk directly—no new frameworks to learn.
  • Seamless Switching: Compatible with all Beta features, including context-management and thinking modes.
import Anthropic from "@anthropic-ai/sdk";

// Just modify baseURL to switch seamlessly to Novita
const anthropic = new Anthropic({
  baseURL: "https://api.novita.ai/anthropic",
  apiKey: process.env.NOVITA_API_KEY,
});

// All Anthropic SDK usage remains unchanged
const response = await anthropic.messages.create({
  model: "zai-org/glm-4.7",
  max_tokens: 4096,
  messages: [{ role: "user", content: "Hello, World!" }],
});

2. Cloud-Isolated “Sandbox Laboratory”

Novita Sandbox provides instant-launch Linux environments with file system access, network communication, and background processes:

  • Secure Isolation: Each request runs in an independent sandbox, preventing code contamination.
  • Full-Stack Capabilities: Built-in Node.js, Python, and Jupyter environments with dynamic npm and pip installation support.
  • Instant Preview: One-click public HTTPS port exposure—view generated pages immediately.
import { Sandbox } from "novita-sandbox/code-interpreter";

// Create an isolated cloud environment in seconds
const sandbox = await Sandbox.create({ timeoutMs: 10 * 60 * 1000 });

// Write files
await sandbox.files.write("index.html", "<h1>Hello from Sandbox!</h1>");

// Start a background service and get a public URL
const handle = await sandbox.commands.run("npx http-server -p 3000", { background: true });
const publicUrl = `https://${sandbox.getHost(3000)}`;

console.log(`🌐 Preview URL: ${publicUrl}`);

3. Context Self-Healing and Intelligent Awareness

Leveraging Claude’s Tool Use capabilities, Agents can:

  • Adapt and Repair: When runtime errors occur, the Agent sees stderr and automatically rewrites the code.
  • Optimize Memory: Combined with contextManagement strategies, the system automatically clears old code blocks to stay focused.
// Enable the context-management Beta feature
// Reference: https://platform.claude.com/docs/en/build-with-claude/context-editing
const response = await anthropic.beta.messages.create({
  model: "zai-org/glm-4.7",
  max_tokens: 4096,
  betas: ["context-management-2025-06-27"],
  contextManagement: {
    edits: [
      {
        type: "clear_tool_uses_20250919",
        trigger: { type: "input_tokens", value: 10000 },  // Trigger cleanup when exceeding 10k tokens
        keep: { type: "tool_uses", value: 2 },            // Keep the last 2 tool calls
        clear_tool_inputs: true,                          // Also clear tool inputs
      },
    ],
  },
  tools: TOOLS,
  messages: conversationHistory,
});

How It Works: When conversation context exceeds the set threshold, the API automatically clears earlier tool call results while preserving recent critical information. This prevents “memory pollution” that degrades Agent performance.

Use Cases: Endless Possibilities

ScenarioWhat Novita Sandbox Adds
Interactive Web LabGenerate React/Tailwind pages from a single sentence; preview instantly.
Intelligent Data AnalysisDynamically run Python to generate charts with Pandas and Matplotlib.
AI Automated TestingRun test scripts in isolated environments; auto-capture and fix bugs.
Personalized IDE BackendProvide each user with an independent cloud executor—zero ops overhead.
Self-Healing Code WorkflowsTest generated API code in a closed loop, ensuring it runs correctly before delivery.

Quick Start: Build an Interactive Agent in Three Steps

No complex configuration needed—Novita makes development simple.

Step 1: Minimal Installation

npm install @anthropic-ai/sdk novita-sandbox dotenv open

Step 2: Smart API Key Integration

The project includes interactive key guidance. Even without environment variables, the program prompts you at startup:

// agent_en.ts internal logic
if (!agent.hasApiKey()) {
  const apiKey = await promptForApiKey(rl);
  agent.setApiKey(apiKey);
}

Step 3: One-Click Interactive CLI Launch

Run npm run agent-en to enter interactive mode. Simply enter your requirements, and Anthropic-compatible models will take care of generating code, running services, and opening the browser.

npm run agent-en

Core Code Walkthrough

📌 Tool Definitions: Giving AI “Physical Abilities”

const TOOLS: Anthropic.Beta.Messages.BetaTool[] = [
  {
    name: "write_file",
    description: "Create or modify a file in the sandbox",
    input_schema: {
      type: "object",
      properties: {
        path: { type: "string", description: "File path, e.g., index.html" },
        content: { type: "string", description: "Complete file content" },
      },
      required: ["path", "content"],
    },
  },
  {
    name: "get_preview_url",
    description: "Start the web server and get the preview URL (returns the existing URL if the server is already running)",
    input_schema: { type: "object", properties: {} },
  },
];

📌 Agentic Loop: Process Until Task Completion

async chat(userMessage: string): Promise<void> {
  // Refresh sandbox timeout on each user input
  await this.refreshSandboxTimeout();
  
  this.messages.push({ role: "user", content: userMessage });

  // Agentic Loop—continue processing until no tool calls remain
  let continueLoop = true;
  while (continueLoop) {
    const { response, assistantContent } = await this.streamResponse();
    this.messages.push({ role: "assistant", content: assistantContent });

    // Process tool calls
    const { hasToolUse, toolResults } = await this.processToolCalls(assistantContent);

    if (hasToolUse && toolResults.length > 0) {
      this.messages.push({ role: "user", content: toolResults });
      continueLoop = true;  // Tool calls exist; continue loop
    } else {
      continueLoop = false; // No tool calls; end
    }

    if (response.stop_reason === "end_turn") {
      continueLoop = false;
    }
  }
}

📌 Service Self-Healing: Smart Detection and Auto-Restart

private async handleGetPreviewUrl(): Promise<string> {
  // Verify whether the process is actually alive
  if (this.previewUrl && this.serverHandle) {
    const processAlive = await this.checkServerProcessAlive();
    if (!processAlive) {
      console.log(`⚠️ Server process has exited; restarting...`);
      this.serverHandle = null;
      this.previewUrl = null;
    }
  }

  // Start a new server
  this.serverHandle = await this.sandbox.commands.run(
    `npx -y http-server . -p ${CONFIG.serverPort} -c-1`,
    { background: true }
  );

  // Get the public URL and run a health check
  const host = this.sandbox.getHost(CONFIG.serverPort);
  this.previewUrl = `https://${host}`;
  
  await waitForServer(this.previewUrl, maxRetries, intervalMs);
  await openBrowser(this.previewUrl);
  
  return `Preview URL: ${this.previewUrl}`;
}

Explore the Complete Example

Novita provides a fully functional Claude Agent SDK example with production-ready code patterns. The example demonstrates:

  • Interactive CLI interface with streaming responses
  • Complete tool implementations (file operations, code execution, web server management)
  • Context management with automatic cleanup
  • Error handling and retry logic
  • Service health checks with automatic restart
  • Multi-turn conversation with persistent state

GitHub Repository: Novita-CollabHub/examples/claude-agent

Quick Start with the Example:

# Clone the repository
git clone https://github.com/novitalabs/Novita-CollabHub.git
cd Novita-CollabHub/examples/claude-agent

# Install dependencies
npm install

# Set your API key
export NOVITA_API_KEY=your_api_key_here

# Run the interactive agent
npm run agent-en

Multi-Turn Dialogue Demo

Here’s a complete multi-turn dialogue example showing how the Agent iteratively refines a page based on user feedback:

Round 1: Build a to-do list app

User Input: Build a to-do list app

Build a to-do list app

Round 2: Change to a Stardew Valley Style

User Input: Change to a Stardew Valley style

Change to a Stardew Valley Style

Round 3: Add More function

User Input: Add more function

Add More function

Conclusion

Deploying Claude Agent SDK in production requires infrastructure that traditional cloud platforms weren’t designed to provide. Novita Sandbox provides a production-ready infrastructure that integrates seamlessly with the Claude Agent SDK, giving your agents the “hands” they need to work in the physical world by offering:

  • E2B-compatible cloud execution environment for seamless integration with existing tools
  • Native Anthropic-compatible endpoint requiring zero refactoring—just change the baseURL
  • Secure container isolation for untrusted code execution
  • Instant provisioning with pre-configured runtimes
  • Public URL exposure for generated web applications
  • Background process management for long-running services

Start building stateful AI agents today:

Novita AI is a leading AI cloud platform that provides developers with easy-to-use APIs and affordable, reliable GPU infrastructure for building and scaling AI applications.