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