Bun runtime for [Freestyle](https://freestyle.sh) VMs.
npm install @freestyle-sh/with-bunBun runtime for Freestyle VMs.
``bash`
npm install @freestyle-sh/with-bun freestyle-sandboxes
`typescript
import { freestyle } from "freestyle-sandboxes";
import { VmBun } from "@freestyle-sh/with-bun";
const { vm } = await freestyle.vms.create({
with: {
js: new VmBun(),
},
});
const res = await vm.js.runCode({
code: "console.log(JSON.stringify({ hello: 'world' }));"
});
console.log(res);
// { result: { hello: 'world' }, stdout: '{"hello":"world"}\n', statusCode: 0 }
`
`typescript`
new VmBun({
version: "1.1.0", // Optional: specific Bun version (default: latest)
})
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| version | string | undefined | Bun version to install. If not specified, installs the latest version. |
Executes JavaScript/TypeScript code in the Bun runtime.
Returns: Promise
`typescript`
type RunCodeResponse
result: Result; // Parsed JSON from stdout (if valid JSON)
stdout?: string; // Raw stdout output
stderr?: string; // Raw stderr output
statusCode?: number; // Exit code
};
Installs npm packages using Bun.
`typescript
// Install from package.json in current directory
await vm.js.install();
// Install from package.json in specific directory
await vm.js.install({ directory: "/app" });
// Install specific packages
await vm.js.install({ deps: ["lodash", "express"] });
// Install with specific versions
await vm.js.install({ deps: { "lodash": "^4.0.0", "express": "~5.0.0" } });
// Install as dev dependencies
await vm.js.install({ deps: ["typescript"], dev: true });
// Install globally
await vm.js.install({ global: true, deps: ["typescript"] });
`
Returns: Promise
`typescript``
type InstallResult = {
success: boolean;
stdout?: string;
stderr?: string;
};