Skip to main content

Install

bun add buntime.sh

Initialize

import { Buntime } from 'buntime.sh';

const client = new Buntime({
  apiKey: process.env.BUNTIME_API_KEY
});

Create a Session

const session = await client.sessions.create();
console.log('Session ID:', session.id);

Execute Code

const result = await client.execute({
  sessionId: session.id,
  code: `
    const sum = [1, 2, 3, 4, 5].reduce((a, b) => a + b, 0);
    console.log('Sum:', sum);
  `
});

console.log(result.stdout); // "Sum: 15"

Work with Files

await client.files.write({
  sessionId: session.id,
  path: 'hello.ts',
  content: 'export const greet = (name: string) => `Hello, ${name}!`;'
});

const result = await client.execute({
  sessionId: session.id,
  code: 'import { greet } from "./hello"; console.log(greet("World"));'
});

Clean Up

await client.sessions.delete({ sessionId: session.id });

Next Steps

See the full SDK introduction for complete examples and best practices.