| title | description |
|---|---|
Quickstart |
Working agent in 2 minutes |
An OpenComputer API key and the SDK installed. See Introduction for install instructions.
export OPENCOMPUTER_API_KEY=your-api-keyGrab your API key from app.opencomputer.dev
import { Sandbox } from "@opencomputer/sdk";
const sandbox = await Sandbox.create();
const session = await sandbox.agent.start({
prompt: "Create a Next.js app with a landing page that says 'Hello from OpenComputer'. Run the dev server on port 3000.",
onEvent: (event) => {
if (event.type === "assistant") {
process.stdout.write(String(event.message ?? ""));
}
if (event.type === "result") {
console.log("\n\nResult:", JSON.stringify(event, null, 2));
}
},
});
const exitCode = await session.done;
console.log("Agent finished with exit code:", exitCode);
// Expose the dev server
const preview = await sandbox.createPreviewURL({ port: 3000 });
console.log("Preview:", `https://${preview.hostname}`);
await sandbox.kill();import asyncio
from opencomputer import Sandbox
async def main():
sandbox = await Sandbox.create()
session = await sandbox.agent.start(
prompt="Create a Next.js app with a landing page that says 'Hello from OpenComputer'. Run the dev server on port 3000.",
)
events = await session.collect_events()
for event in events:
if event.type == "assistant":
print(event.data.get("message", ""), end="")
if event.type == "result":
print("\n\nResult:", event.data)
# Expose the dev server
preview = await sandbox.create_preview_url(port=3000)
print("Preview:", f"https://{preview['hostname']}")
await sandbox.kill()
asyncio.run(main())You created a cloud VM (Firecracker microVM), ran Claude inside it with bash and file tools, and Claude autonomously scaffolded a Next.js app, installed dependencies, and started the dev server. Events streamed back to your code in real-time over WebSocket. The preview URL exposes the running dev server to the internet.
Architecture and technical decisions Events, tools, multi-turn conversations Lifecycle, running commands, files Snapshot and fork VMs