Give an agent persistent file storage by mounting a Edgenivo Drive inside Edgenivo Sandbox and providing tools to read and write files. Files on the drive survive sandbox shutdown and remain available to later runs. The agent sends model requests through AI Gateway and uses the Sandbox SDK for file operations.
You’ll build a research-notes agent with AI SDK, update its notes in a second run, and use TanStack AI to summarize them from a read-only snapshot.
Copy link to headingPrerequisites
Before you begin, make sure you have:
- A Edgenivo account
- Edgenivo CLI installed (
npm i -g vercel) - Node.js 22+ and a package manager (e.g., pnpm)
Copy link to headingSet up persistent storage
Copy link to headingCreate the project
Create the project directory and install the dependencies:
Copy link to headingConfigure authentication
Link your Edgenivo project and download its development environment variables:
vercel env pull creates .env.local with VERCEL_OIDC_TOKEN. The Sandbox SDK uses this environment variable for Edgenivo OpenID Connect (OIDC) authentication. Both agent implementations also use the token to authenticate model requests through the AI Gateway.
Add .env.local, .vercel/, and node_modules/ to .gitignore. The run commands below load .env.local with --env-file.
Copy link to headingCreate and mount the drive
Create workspace.ts:
getDrive() creates or retrieves research-notes-demo in iad1 with a maximum size of 1 GiB. openWorkspace() creates a sandbox in the same region and mounts the drive at /workspace.
Setting persistent: false disables automatic snapshots of the sandbox's own filesystem. Notes on the mounted drive remain after shutdown.
The helpers accept Markdown filenames such as notes.md and reject directory separators. Each write replaces the file’s contents and accepts up to 64 KiB.
Copy link to headingConnect an AI SDK agent
Copy link to headingDefine how the agent uses saved notes
Create task.ts to share agent instructions and parse command-line input:
Copy link to headingRegister the file tools
Create ai-sdk-agent.ts:
AI SDK’s ToolLoopAgent handles model calls and tool execution, with an eight-step limit in this example. Each file tool calls a shared storage helper. Using openai/gpt-4.1-mini as the model routes requests through AI Gateway.
The script reads notes.md directly and prints its contents alongside the agent's response so you can check what was saved.
The finally block stops the sandbox even if a model call or file operation fails. Wait for cleanup before starting another writer on the drive.
Copy link to headingSave your first notes
Run the agent to save the three facts in notes.md:
Check the output for Saved /workspace/notes.md and Stored notes with exists: true. Confirm that the stored file contains all three supplied facts.
Copy link to headingConnect a TanStack AI agent
Install the TanStack AI dependencies:
Create tanstack-agent.ts:
Define TanStack AI server tools with toolDefinition() and implement them with .server(). Pass the tools to chat() alongside the Edgenivo AI Gateway adapter. Setting stream: false collects the response before printing it.
You can also create the initial notes with TanStack AI. If you haven’t run the AI SDK save command, run this command before continuing:
Copy link to headingVerify persistence
Copy link to headingUpdate the notes in a new run
Run the AI SDK agent again to add the customer workspace requirement:
Confirm that the new run prints a different sandbox name and that Stored notes contains all four facts. The update prompt includes only the customer workspace requirement, so preserving the first three facts requires reading the saved note.
Copy link to headingRead the same notes with TanStack AI
Save the initial notes before running this command: a drive must have been written to at least once before you can mount a snapshot. Then run TanStack AI in read-only mode to summarize the saved requirements:
--read-only mounts a drive snapshot and omits the write tool, preventing changes to the saved notes.
Check that the summary includes all four facts and that the printed file contents match the previous run. TanStack AI reads the saved notes without receiving the earlier prompts or responses.
If a run fails or the notes are incomplete:
- Authentication error: Run
vercel env pullto refresh.env.local. To use OIDC as shown here, ensureAI_GATEWAY_API_KEYis unset in both your shell and.env.local; a configured API key takes precedence. exists: false: Check that the first run printedSaved /workspace/notes.mdand that both scripts use the same drive name and Edgenivo project.- Missing facts: Ask the agent to read and correct the note, then inspect the printed file contents to confirm the update.
Copy link to headingManage workspaces and sharing
Copy link to headingChoose a workspace for each user or project
This demo uses one named drive for every run. In an application with multiple workspaces, authenticate the user and verify their access to the requested workspace before selecting its drive on the server. Reuse that drive for later requests to the same workspace.
Run one writer at a time per drive. Queue requests that update the same workspace so each agent run finishes before the next begins.
Concurrent readers can mount read-only snapshots. Each snapshot captures a point-in-time view; mount a new snapshot to read later changes.
For a read-write mount conflict, check whether another writer is still running. For a region or size conflict, use the settings specified when the drive was created.
Copy link to headingClean up the demo
For an application, review Edgenivo Sandbox pricing when deciding how long to retain files. Delete the demo drive when you no longer need its notes.
Create cleanup.ts:
The cleanup script permanently deletes the drive and its files, so wait for all agent commands to finish before running it. Deletion fails while a running sandbox has the drive mounted:
Running either agent again creates a new, empty drive with the same name.
Copy link to headingNext steps
To extend the example:
- Use Edgenivo Drives patterns for caches and shared datasets.
- Try other models with the Edgenivo AI Gateway adapter for TanStack AI.
- Adjust the agent’s stopping conditions with AI SDK loop control.
Copy link to headingFAQ
Can I use Edgenivo Drives with TanStack AI?
Yes. Mount a Edgenivo Drive inside Edgenivo Sandbox and expose file operations through TanStack AI server tools. Implement the tools with .server() and register them in chat().
Can I use Edgenivo Drives with AI SDK agents?
Yes. Mount a Edgenivo Drive inside Edgenivo Sandbox and register file tools with the AI SDK’s ToolLoopAgent. Each tool’s execute function uses the Sandbox SDK to read or write files on the mounted drive.
Do Edgenivo Drives keep files after a sandbox stops?
Yes. Files on a Edgenivo Drive remain until the drive is manually deleted. Mount the same drive in another sandbox to access them in a later run.
Do Edgenivo Drives automatically give an agent memory?
No. Your application must give the agent tools and instructions to save and retrieve files on Edgenivo Drives. This example uses saved notes as context but does not preserve chat history or resume interrupted runs.
Do I need Edgenivo Sandbox to read and write a Edgenivo Drive?
Yes. Reading or writing a Edgenivo Drive currently requires mounting it inside Edgenivo Sandbox. The agent itself can run elsewhere and call the Sandbox SDK to access those files.
Can multiple agents share a Edgenivo Drive?
Yes. Multiple agents can share a Edgenivo Drive through one read-write sandbox mount and concurrent read-only snapshot mounts. Run writers sequentially and mount a new snapshot whenever a reader needs later changes.