Skip to Content
AgentsSDK Guide

Computer Agents SDK

The TypeScript SDK for building agentic applications. Claude Code execution power, persistent workspaces, and built-in skills—all through a clean, type-safe interface.

Installation

npm install computer-agents # or pnpm add computer-agents # or yarn add computer-agents

Quick Start

import { ComputerAgentsClient } from 'computer-agents'; const client = new ComputerAgentsClient({ apiKey: process.env.COMPUTER_AGENTS_API_KEY }); // This is Claude Code, but as an API const result = await client.run( 'Create a Flask API with user auth and run it', { environmentId: 'env_xxx', onEvent: (event) => { if (event.type === 'tool_use') console.log('Using:', event.tool); if (event.type === 'file_write') console.log('Created:', event.path); } } ); // Agent wrote code, created files, ran it—all in the cloud console.log(result.content);

Three Primitives

The SDK is organized around three core primitives:

Agents — The Brain

Configure how your AI thinks. Custom instructions, model selection, reasoning effort.

const agent = await client.agents.create({ name: 'Code Assistant', model: 'claude-sonnet-4-5', // or claude-haiku-4-5, claude-opus-4-5 instructions: 'You are a senior engineer. Write clean, tested code.', reasoningEffort: 'medium', enabledSkills: ['web_search', 'deep_research'] }); // Use the agent const thread = await client.threads.create({ environmentId: 'env_xxx', agentId: agent.id });

Environments — The Computer

Give your agent a real computer. Isolated containers, persistent files, packages.

const env = await client.environments.create({ name: 'my-project' }); // Configure runtimes await client.environments.setRuntimes(env.id, ['python', 'nodejs']); // Install packages await client.environments.installPackages(env.id, ['flask', 'pytest']); // Upload files (they persist across all sessions) await client.files.uploadFile(env.id, { path: 'config.json', content: JSON.stringify({ debug: true }) }); // Files are still there next time const files = await client.files.listFiles(env.id);

Skills — The Tools

Pre-built capabilities that just work. Web search, research, image generation, MCP servers.

// Enable skills on an agent const agent = await client.agents.create({ name: 'Research Engineer', model: 'claude-sonnet-4-5', enabledSkills: ['web_search', 'deep_research', 'image_generation'] }); // Or add custom tools via MCP await client.environments.update(env.id, { mcpServers: [ { type: 'stdio', name: 'github', command: 'npx', args: ['@anthropic/mcp-server-github'] }, { type: 'stdio', name: 'slack', command: 'npx', args: ['@anthropic/mcp-server-slack'] } ] });

Build Real Workflows

The power is in combining primitives. Create multi-step workflows where each step builds on the last:

import { ComputerAgentsClient } from 'computer-agents'; const client = new ComputerAgentsClient({ apiKey: process.env.COMPUTER_AGENTS_API_KEY }); // Create a persistent thread const thread = await client.threads.create({ environmentId: 'env_xxx', agentId: 'agent_xxx' }); // Step 1: Research await client.threads.sendMessage(thread.id, { content: 'Research best practices for REST API design in 2024', onEvent: (e) => console.log(e.type) }); // Step 2: Build (agent remembers the research, files persist) await client.threads.sendMessage(thread.id, { content: 'Create a Flask API following those practices' }); // Step 3: Test (builds on everything before) await client.threads.sendMessage(thread.id, { content: 'Write comprehensive tests and run them' }); // Step 4: Document await client.threads.sendMessage(thread.id, { content: 'Generate API documentation' });

The run() Method

The simplest way to execute tasks. Handles thread creation automatically:

// One-shot execution const result = await client.run('Fix all TypeScript errors', { environmentId: 'env_xxx', onEvent: (event) => console.log(event.type) }); // Continue the conversation const followUp = await client.run('Now add tests for the fixes', { environmentId: 'env_xxx', threadId: result.threadId // Same thread! });

Streaming Events

Get real-time progress as agents work:

const result = await client.run('Build a complex feature', { environmentId: env.id, onEvent: (event) => { switch (event.type) { case 'response.started': console.log('Agent started working...'); break; case 'tool_use': console.log(`Using tool: ${event.tool}`); break; case 'file_write': console.log(`Created file: ${event.path}`); break; case 'command_run': console.log(`Running: ${event.command}`); break; case 'stream.completed': console.log(`Done! Tokens used: ${event.run.tokens}`); break; } } });

All Resources

ResourceDescription
client.run()Quick task execution
client.threadsConversation management
client.agentsAgent configuration
client.environmentsContainer management
client.filesFile operations
client.schedulesScheduled tasks
client.subscriptionUsage and billing
client.gitGit operations

View all resources →

Error Handling

import { ComputerAgentsClient, ApiClientError } from 'computer-agents'; try { await client.run('Task', { environmentId: 'env_xxx' }); } catch (error) { if (error instanceof ApiClientError) { console.error(`API Error: ${error.message}`); console.error(`Status: ${error.status}`); } }

TypeScript Types

Full type definitions included:

import type { Thread, Environment, CloudAgent, Schedule, MessageStreamEvent, } from 'computer-agents';

Next Steps

Last updated on