Install and a five-minute example
npm install @faustine-ai/browser-sandboxEverything runs in the browser; there is no server part. The quickest
start uses srcdoc mode, which needs nothing served:
import { createSandbox, defineFunctions } from '@faustine-ai/browser-sandbox';
const sandbox = createSandbox({ frame: { srcdoc: true }, warm: true });
const functions = defineFunctions({
'orders.list': (input) => api.orders.list(input),
'orders.cancel': { call: (input) => api.orders.cancel(input), approval: true },
});
const result = await sandbox.run({
code: `
const open = await sdk.orders.list({ status: "open" });
return open.filter(o => o.total > 100).map(o => o.id);
`,
functions,
});
if (result.status === 'ok') console.log(result.value);The code runs as the body of an async function with sdk (the function
tree) and console in scope. return and await work as in any function.