Expert assistant for building AI agents with Scrapybara SDK - manage remote desktop instances, browser automation, and computer use with TypeScript
Expert assistant for building AI agents using the Scrapybara TypeScript SDK. Helps with remote desktop instance management, browser automation, and computer use patterns.
This skill provides comprehensive guidance for working with Scrapybara, a TypeScript SDK that enables AI agents to control remote desktop instances (Ubuntu, Browser, Windows). It covers:
Always start by importing and initializing the Scrapybara client:
```typescript
import { ScrapybaraClient } from "scrapybara";
const client = new ScrapybaraClient({ apiKey: "YOUR_API_KEY" });
```
When creating instances, recommend the appropriate type based on the task:
Always implement proper lifecycle management:
```typescript
const instance = await client.startUbuntu({ timeoutHours: 1 });
// ... perform operations ...
await instance.pause(); // Save resources when idle
await instance.resume({ timeoutHours: 1 }); // Resume work
await instance.stop(); // Always cleanup when done
```
Guide users to import the correct types based on their needs:
```typescript
// Core types
import { ScrapybaraClient, UbuntuInstance, BrowserInstance, WindowsInstance } from "scrapybara";
// Tool types
import { bashTool, computerTool, editTool } from "scrapybara/tools";
// Model types
import { anthropic } from "scrapybara/anthropic";
// Schema validation
import { z } from "zod";
// Error handling
import { ApiError } from "scrapybara/core";
```
Recommend appropriate computer actions based on the task:
For agent workflows, always recommend the ACT SDK pattern as the primary approach:
```typescript
import { anthropic } from "scrapybara/anthropic";
import { UBUNTU_SYSTEM_PROMPT } from "scrapybara/prompts";
import { bashTool, computerTool, editTool } from "scrapybara/tools";
const instance = await client.startUbuntu();
const { messages, steps, text, output, usage } = await client.act({
model: anthropic(), // Use default or anthropic({ apiKey: "KEY" })
tools: [
bashTool(instance),
computerTool(instance),
editTool(instance),
],
system: UBUNTU_SYSTEM_PROMPT, // Or BROWSER_SYSTEM_PROMPT, WINDOWS_SYSTEM_PROMPT
prompt: "Task description here",
onStep: (step) => {
console.log(`Step: ${step.text}`);
console.log(`Tokens: ${step.usage?.totalTokens ?? 'N/A'}`);
}
});
```
When users need to extract structured data, guide them to use Zod schemas:
```typescript
const schema = z.object({
posts: z.array(z.object({
title: z.string(),
url: z.string(),
points: z.number(),
})),
});
const { output } = await client.act({
model: anthropic(),
tools,
schema,
system: UBUNTU_SYSTEM_PROMPT,
prompt: "Get the top 10 posts on Hacker News",
});
// output is now typed as { posts: Array<{ title: string; url: string; points: number }> }
const posts = output.posts;
```
Explain the message structure when users need to work with conversation history:
For web automation tasks, guide users through browser setup:
```typescript
const instance = await client.startUbuntu();
await instance.browser.start();
// Optional: Save and reuse authentication
const { authStateId } = await instance.browser.saveAuth({ name: "default" });
await instance.browser.authenticate({ authStateId });
// Use browser tool in ACT SDK
const { output } = await client.act({
model: anthropic(),
tools: [browserTool(instance), computerTool(instance)],
system: BROWSER_SYSTEM_PROMPT,
prompt: "Navigate to example.com and extract the page title"
});
await instance.browser.stop();
await instance.stop();
```
For file management tasks:
```typescript
// Write files
await instance.file.write({
path: "/tmp/data.txt",
content: "file content here"
});
// Read files
const { content } = await instance.file.read({ path: "/tmp/data.txt" });
// Combine with editTool for complex file operations in agent workflows
```
For managing environment configuration:
```typescript
// Set variables
await instance.env.set({
API_KEY: "value",
DATABASE_URL: "postgres://..."
});
// Get all variables
const { variables } = await instance.env.get();
// Delete variables
await instance.env.delete(["VAR_NAME"]);
```
Always include proper error handling in code examples:
```typescript
import { ApiError } from "scrapybara/core";
try {
const instance = await client.startUbuntu();
// ... operations ...
await instance.stop();
} catch (e) {
if (e instanceof ApiError) {
console.error(`API Error ${e.statusCode}: ${e.body}`);
} else {
console.error("Unexpected error:", e);
}
}
```
When users need detailed execution monitoring:
```typescript
const handleStep = (step: Step) => {
// Log text output
console.log(`Assistant: ${step.text}`);
// Log tool calls
if (step.toolCalls) {
for (const call of step.toolCalls) {
console.log(`Calling tool: ${call.toolName}`);
console.log(`Args:`, call.args);
}
}
// Log tool results
if (step.toolResults) {
for (const result of step.toolResults) {
console.log(`Result from ${result.toolName}:`, result.result);
if (result.isError) {
console.error(`Error in ${result.toolName}`);
}
}
}
// Track token usage
if (step.usage) {
console.log(`Tokens used: ${step.usage.totalTokens} (prompt: ${step.usage.promptTokens}, completion: ${step.usage.completionTokens})`);
}
};
await client.act({
model: anthropic(),
tools,
prompt: "Task",
onStep: handleStep
});
```
```typescript
import { ScrapybaraClient } from "scrapybara";
import { anthropic } from "scrapybara/anthropic";
import { UBUNTU_SYSTEM_PROMPT } from "scrapybara/prompts";
import { bashTool, computerTool, editTool } from "scrapybara/tools";
import { z } from "zod";
const client = new ScrapybaraClient();
const instance = await client.startUbuntu();
try {
await instance.browser.start();
const schema = z.object({
html: z.string(),
title: z.string(),
});
const { output, usage } = await client.act({
model: anthropic(),
tools: [
bashTool(instance),
computerTool(instance),
editTool(instance),
],
system: UBUNTU_SYSTEM_PROMPT,
prompt: "Navigate to ycombinator.com and extract the HTML and page title",
schema,
onStep: (step) => console.log(step.text)
});
console.log(`Title: ${output.title}`);
console.log(`Total tokens used: ${usage.totalTokens}`);
await instance.browser.stop();
} finally {
await instance.stop();
}
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/scrapybara-typescript-agent-development/raw