/sandbox-sessions.
Prerequisites
- A Veryfront Cloud token (
VERYFRONT_API_TOKEN) or a self-hosted/sandbox-sessionsAPI and matchingVERYFRONT_API_URL. - A reachable network from the process that calls
Sandbox.create().
Create a sandbox session
UseSandbox.create() with sandbox API credentials. In local development,
self-hosted apps, CI, and other runtimes outside a Veryfront-hosted request,
provide credentials explicitly. Set VERYFRONT_API_TOKEN, and set
VERYFRONT_API_URL when you need a non-default API endpoint.
Inside a Veryfront-hosted request, the client can use request-scoped
credentials automatically. In that path, you do not need to set
VERYFRONT_API_TOKEN separately for the request.
getProjectId() so lazy exec and async run calls inherit the latest project reference automatically:
authToken explicitly. This can be a
JWT or a Studio-generated API key.
For project-scoped billing or isolation, pass projectId when creating the
session.
Execute commands
Buffered execution:Read and write files
Lifecycle best practices
- Always call
await sandbox.close()infinallyblocks. - Prefer
Sandbox.createLazy()for agent-style workflows that may not need a session every run. - Use
sandbox.heartbeat()during long-running sessions to avoid idle timeouts. - Persist
sandbox.idonly when you need reconnect semantics. - Keep auth tokens and API keys server-side only. Do not expose them to browsers.
Example with cleanup
Verify it worked
Run the example above in a Node script with the env vars set. A working sandbox:- Prints
readyto stdout fromexecuteCommand. - Returns
exitCode: 0from the command result. - Releases its session on
sandbox.close()without an error.
Sandbox.create() throws a 401, double-check the API token. If the
session never closes, look in the cloud dashboard for the lingering session
id and close it manually.