Quick Start
Get your first AI agent running in the cloud in under 5 minutes.
Prerequisites
- Node.js 18+ or Bun
- A Computer Agents API key (get one here )
Step 1: Install the SDK
npm install computer-agentsStep 2: Set Your API Key
export COMPUTER_AGENTS_API_KEY="tb_your_api_key_here"Or create a .env file:
COMPUTER_AGENTS_API_KEY=tb_your_api_key_hereStep 3: Create Your First Script
Create a file called hello-agent.mjs:
import { ComputerAgentsClient } from 'computer-agents';
const client = new ComputerAgentsClient();
async function main() {
// Quick setup - creates a default environment if needed
const { environment } = await client.quickSetup();
console.log('Environment ready:', environment.id);
// Run your first task
const result = await client.run('Create a file called hello.py that prints "Hello, World!"', {
environmentId: environment.id,
onEvent: (event) => {
if (event.type === 'response.item.completed') {
console.log('Agent:', event.item.type);
}
}
});
console.log('\nResult:', result.content);
console.log('Thread ID:', result.threadId);
// Check created files
const files = await client.files.listFiles(environment.id);
console.log('\nFiles:', files.map(f => f.path).join(', '));
}
main().catch(console.error);Step 4: Run It
node hello-agent.mjsYou should see output like:
Environment ready: env_abc123
Agent: text
Agent: tool_call
Agent: text
Result: I've created hello.py with the classic "Hello, World!" program.
Thread ID: thread_xyz789
Files: /hello.pyWhat Just Happened?
- Client initialization - The SDK read your API key from the environment
- Quick setup - Created a default cloud environment for execution
- Task execution - Sent the task to a cloud agent via streaming
- File creation - The agent wrote code to your environment’s file system
- Response - You received the result and can continue the conversation
Continue the Conversation
The threadId maintains context. Use it to build on previous work:
// Continue from the previous result
const followUp = await client.run('Add a function that takes a name and prints a greeting', {
environmentId: environment.id,
threadId: result.threadId // Same thread!
});
console.log(followUp.content);Next: Working with Files
Upload files to your environment:
await client.files.uploadFile({
environmentId: environment.id,
filename: 'config.json',
content: JSON.stringify({ debug: true }, null, 2)
});
// Ask the agent to use it
await client.run('Read config.json and print its contents', {
environmentId: environment.id,
threadId: result.threadId
});Download files:
const content = await client.files.getFile(environment.id, 'hello.py');
console.log(content);Complete Quick Start Example
Here’s a more complete example with error handling:
import { ComputerAgentsClient, ApiClientError } from 'computer-agents';
const client = new ComputerAgentsClient({
debug: true // Enable debug logging
});
async function main() {
try {
// Setup
const { environment } = await client.quickSetup({
internetAccess: true
});
// Task 1: Create a project
const r1 = await client.run('Create a simple Express.js server with a /health endpoint', {
environmentId: environment.id,
onEvent: (e) => console.log(`[${e.type}]`)
});
console.log('\n--- Task 1 Complete ---');
console.log(r1.content);
// Task 2: Add features
const r2 = await client.run('Add a /api/users endpoint that returns sample user data', {
environmentId: environment.id,
threadId: r1.threadId
});
console.log('\n--- Task 2 Complete ---');
console.log(r2.content);
// Task 3: Add tests
const r3 = await client.run('Create Jest tests for the endpoints', {
environmentId: environment.id,
threadId: r1.threadId
});
console.log('\n--- Task 3 Complete ---');
console.log(r3.content);
// List all files
const files = await client.files.listFiles(environment.id);
console.log('\n--- Files Created ---');
files.forEach(f => console.log(`${f.type === 'directory' ? '📁' : '📄'} ${f.path}`));
} catch (error) {
if (error instanceof ApiClientError) {
console.error('API Error:', error.message);
console.error('Status:', error.status);
} else {
throw error;
}
}
}
main();TypeScript Usage
The SDK has full TypeScript support:
import { ComputerAgentsClient } from 'computer-agents';
import type { Environment, Thread, MessageStreamEvent } from 'computer-agents';
const client = new ComputerAgentsClient();
async function main() {
const environments: Environment[] = await client.environments.list();
const thread: Thread = await client.threads.create({
environmentId: environments[0].id
});
const result = await client.threads.sendMessage(thread.id, {
content: 'Hello!',
onEvent: (event: MessageStreamEvent) => {
console.log(event.type);
}
});
}Next Steps
Now that you have the basics down:
- API Resources - Learn about all available resources
- Streaming & Events - Handle events in real-time
- Advanced Patterns - Production patterns and best practices
Last updated on