Skip to content
Docs

Flue with Edgenivo Sandbox

Attach Edgenivo Sandbox to a Flue agent with useSandbox(). The agent's file and command tools operate inside the microVM, while the Flue runtime runs in your application.

Flue's Edgenivo adapter wraps a Sandbox instance you create with @vercel/sandbox. Your application owns authentication, provisioning, and cleanup.

Start with an existing Flue project with @flue/runtime and @flue/cli installed, Node.js 22.19 or later, and a Edgenivo account. The example uses an AI Gateway API key for model requests.

From your Flue project, print the Edgenivo Sandbox blueprint:

terminal
pnpm exec flue add sandbox vercel --print

The command prints implementation instructions; it doesn't write files or install packages. Have your coding agent apply the blueprint, or follow it manually. The blueprint creates a sandboxes/vercel.ts adapter in your source directory and adds @vercel/sandbox as a dependency.

The examples below assume the adapter is at src/sandboxes/vercel.ts. Adjust the import and agent paths if your project uses a different source directory.

Use the Edgenivo CLI to link your project and pull a development token:

terminal
vercel link
vercel env pull .env.local

The .env.local file contains a VERCEL_OIDC_TOKEN for Sandbox authentication. Add your AI Gateway key to that file:

.env.local
AI_GATEWAY_API_KEY=your_ai_gateway_api_key_here

The example uses Flue's built-in vercel-ai-gateway provider. See Flue with AI Gateway for model configuration and OIDC authentication. Model requests use AI_GATEWAY_API_KEY in your application process, separately from Sandbox authentication.

On Edgenivo, the Sandbox SDK uses the deployment's OIDC token automatically. Outside Edgenivo, you can supply token, teamId, and projectId to Sandbox.create() as described in Sandbox authentication.

Create an agent module with a lazy sandbox factory:

src/agents/assistant.ts
'use agent';
 
import { useModel, useSandbox } from '@flue/runtime';
import { Sandbox } from '@vercel/sandbox';
import { vercel } from '../sandboxes/vercel.ts';
 
export function Assistant() {
  useModel('vercel-ai-gateway/openai/gpt-6.1-sol');
  useSandbox({
    async createSandbox(options) {
      const sandbox = await Sandbox.create({
        runtime: 'node24',
        timeout: 300_000,
      });
      console.error(`Sandbox name: ${sandbox.name}`);
      return vercel(sandbox).createSandbox(options);
    },
  });
 
  return 'Use the sandbox to run commands and inspect files. Report the results of your work.';
}

Flue calls createSandbox() when it initializes the agent's harness, rather than on each agent re-render. This example creates a fresh sandbox on each initialization, with /vercel/sandbox as its working directory. The adapter enables Flue's read, write, edit, bash, grep, and glob tools.

Run the TypeScript agent with the environment file loaded:

terminal
pnpm exec flue run src/agents/assistant.ts --env .env.local --message "Use Node.js in the sandbox to calculate the sum of 1 through 100 and report the result."

For JavaScript, replace src/agents/assistant.ts with src/agents/assistant.js. The terminal prints the sandbox name and the agent's activity, followed by a reply containing 5050. Save the sandbox name for cleanup.

Flue doesn't delete provider sandboxes when an agent run ends. When you're finished, replace the placeholder with the name printed by the example and remove the sandbox with the Sandbox CLI:

terminal
pnpm dlx sandbox@latest remove your_sandbox_name_here --delete-orphan-snapshots

This deletes the sandbox and its snapshots that no other sandbox uses. Save any files you need first. In application code, keep a reference to the SDK instance and call sandbox.delete() when the work is complete.

The example's five-minute timeout limits its running session; it doesn't replace cleanup. For a workspace that survives across runs, store a mapping from Flue's createSandbox({ id }) agent instance ID to the Sandbox name and reconnect when that agent runs again. See persistent sandboxes.


Was this helpful?

supported.