import { OneCLI } from "@onecli-sh/sdk";
import { Sandbox } from "e2b";
const onecli = new OneCLI(); // reads ONECLI_API_KEY
// 1. An agent on your Personal vault. It ends by itself after an hour.
const agent = await onecli.agents.create({
vaultName: "Personal",
provider: "e2b",
ttlSeconds: 3600,
});
// 2. The sandbox: the agent's settings, and a network to OneCLI only.
const sandbox = await Sandbox.create({
envs: agent.env,
network: {
allowOut: agent.allowHosts,
denyOut: ({ allTraffic }) => [allTraffic],
},
timeoutMs: 3600 * 1000,
});
try {
// 3. Once: write the certificate files that agent.env points at.
await sandbox.commands.run(agent.setupCommand);
// httpbin.org/bearer answers 401 with no key.
// 200 means the gateway added the Test key.
const call = await sandbox.commands.run(
'curl -s -o /dev/null -w "%{http_code}" https://httpbin.org/bearer',
);
console.log(call.stdout); // 200
} finally {
await sandbox.kill();
await agent.disconnect();
}