Skip to main content

Prerequisites

An OpenComputer API key and the SDK installed. See Introduction for install instructions.
export OPENCOMPUTER_API_KEY=your-api-key

Run an Agent

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();

What Just Happened

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.

Next Steps