import { Daytona } from "@daytonaio/sdk";
import { Mesa } from "@mesadev/sdk";
const mesa = new Mesa({ apiKey: process.env.MESA_API_KEY });
const daytona = new Daytona({ apiKey: process.env.DAYTONA_API_KEY });
// --- Outside the sandbox: set up Mesa resources ---
// Create a repo (or use an existing one)
const repo = await mesa.repos.create({ name: "agent-workspace" });
// Create a scoped, short-lived API key for the sandbox
const ephemeralKey = await mesa.apiKeys.create({
name: "sandbox-session",
scopes: ["read", "write"],
expires_in_seconds: 3600, // 1 hour
// Optional: scope the key to a specific repo for better security
// repo_ids: [repoId1, repoId2, ...],
});
// --- Inside the sandbox: install and mount Mesa ---
const sandbox = await daytona.create(
{
image: declarativeImage,
},
// ... with any other Daytona sandbox creation options
)
// Install the Mesa CLI
await sandbox.process.executeCommand(
"curl -fsSL https://mesa.dev/install.sh | sh"
);
// Write the Mesa config file
const mesaConfig = `
mount-point = "/home/daytona/mesa/mnt"
[organizations.my-org]
api-key = "${ephemeralKey.key}"
`.trim();
await sandbox.fs.uploadFile(
Buffer.from(mesaConfig),
"/home/daytona/.config/mesa/config.toml"
);
// Start MesaFS as a background daemon,
// mounting your repos at the mount point you specified in the config file
await sandbox.process.executeCommand("mesa mount --daemonize");
// --- Run your agent ---
await sandbox.process.executeCommand(
'cd /home/daytona/mesa/mnt/my-org/agent-workspace \
&& claude "Implement the feature described in TODO.md"'
);