Start a sandbox from your code and send it files and commands, so generated or untrusted code runs away from your machine. It bills to a project.
Before you start
You need an API key. See Create an API key.
Run a command
- Install the SDK and set your key and the ID of the project to bill (Find your IDs):
Shell
npm install veryfrontexport VERYFRONT_API_KEY=<your key>export VERYFRONT_PROJECT_REFERENCE=<project ID> - Create the script.
ttlModeandttlHoursdelete the sandbox after an hour even if the script stops early:run.mjsimport { Sandbox } from "veryfront/sandbox"; const sandbox = await Sandbox.create({ projectReference: process.env.VERYFRONT_PROJECT_REFERENCE, ttlMode: "duration", ttlHours: 1,}); await sandbox.writeFiles([ { path: "greet.mjs", content: 'console.log("Hello from a sandbox");' },]); const result = await sandbox.runCommand("node greet.mjs");console.log(result.stdout);console.log(await sandbox.readFile("greet.mjs")); await sandbox.delete(); - Run
node run.mjs. You should now see it print "Hello from a sandbox" and the file's contents.
Try it in a sandbox
Install the SDK
Create the script
Check it
Try it out
Good to know
- Each sandbox has its own address, such as
https://3218467769.sandbox.veryfront.com. - Its files are temporary: they can go when it restarts or stops, unless it has a persistent workspace.
- A heartbeat from your code keeps an idle sandbox alive.
ttl_modepicks when it goes:defaultonce it idles,durationafterttl_hours(up to 24), oralways_onuntil you delete it. See Sharing and cleanup.
Troubleshooting
If you see "project_id (or an environment_id that belongs to a project) is required", the sandbox has no project to bill. Set the project's ID, as step 1 does, and run it again.