import { Mesa } from "@mesadev/sdk";
const mesa = new Mesa({ apiKey: process.env.MESA_API_KEY });
// Create a repo (or use an existing one)
const repo = await mesa.repos.create({ name: "agent-workspace" });
// Sign a scoped, self-expiring access token for the sandbox. Signed locally
// from your API key with no network call — your API key never enters the sandbox.
const { token } = await mesa.tokens.create({
scopes: ["read", "write"],
repos: ["my-org/agent-workspace"],
ttl_seconds: 3600, // 1 hour
});
// Start Mesa as a background daemon.
// MESA_ORG configures the org; MESA_API_KEY supplies the credential for this
// process. We pass the short-lived token we minted above, not the raw API key,
// so your long-lived API key never enters the sandbox.
await sandbox.process.exec({
command: `MESA_ORG=my-org MESA_API_KEY=${token} mesa mount -d -y`,
waitForCompletion: true,
});
// Your repos are now at ~/.local/share/mesa/mnt/<org>/<repo>
await sandbox.process.exec({
command: 'cd ~/.local/share/mesa/mnt/my-org/agent-workspace \
&& claude "Implement the feature described in TODO.md"',
waitForCompletion: true,
});