vercel-sandbox

Runs untrusted or AI-generated code in ephemeral Firecracker microVMs via the @vercel/sandbox SDK.

Updated Aug 21, 2025
One-click install
npx skills add https://github.com/Adithiya-S/AI-Study-Companion --skill vercel-sandbox-adithiya-s
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-sandbox
Source: https://github.com/Adithiya-S/AI-Study-Companion/tree/main/.agents/skills/vercel-sandbox/upstream
Command: npx skills add https://github.com/Adithiya-S/AI-Study-Companion --skill vercel-sandbox-adithiya-s

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @vercel/sandbox.

What problem does it solve? Running untrusted, user-submitted, or AI-generated code safely is hard: in-process sandboxes like vm2 have known escapes, and child_process or eval shares your host process. This Skill provisions isolated Firecracker microVMs on demand so risky code executes in a separate Linux VM with its own filesystem, network policy, and lifecycle. ## Core Features & Use Cases - Isolated code execution: Create a VM, run commands, read and write files, expose ports with public preview URLs, and stop or snapshot the environment when finished. - Persistence and snapshots: Persistent sandboxes auto-snapshot their filesystem on stop and resume later; manual snapshots let you boot new VMs with dependencies pre-installed. - Security controls for untrusted code: Apply deny-all or allow-list network policies, broker credentials at the egress firewall so secrets never enter the VM, and isolate multiple agents as separate Linux users. - Use Case: An AI coding agent needs to install dependencies and run tests on generated code. Create a sandbox with a 30-second timeout, vcpus: 1, and a deny-all network policy, run the test suite inside, then stop the VM in a finally block. ## Quick Start Ask the AI to create a Vercel Sandbox, run a Python command inside it, print the output, and stop the sandbox when finished.

Frequently Asked Questions about vercel-sandbox

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run untrusted code safely in Node.js?

Use @vercel/sandbox to run untrusted code in a separate Firecracker microVM instead of in-process options like vm2, which have known escapes. Create a sandbox with Sandbox.create(), run commands with runCommand, and stop the VM in a finally block.

How do I expose a dev server running inside a Vercel Sandbox?

Pass the port in the ports array at create time, start your server bound to 0.0.0.0 rather than 127.0.0.1, then read the public HTTPS URL with sandbox.domain(port). Poll until the port answers before using the URL, since detached commands return before the server listens.

Does Vercel Sandbox work outside the Vercel platform?

Yes. On Vercel it authenticates automatically via OIDC tokens; locally you run vercel link and vercel env pull for a VERCEL_OIDC_TOKEN. For external CI environments, set VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID.

Why does runCommand fail with pipes or redirects?

runCommand executes a binary directly with no shell, so pipes, redirects, &&, and globs do not work. Wrap such commands in bash -c, and always check result.exitCode because non-zero exits do not throw.

What are the limitations of Vercel Sandbox sessions?

Sessions cap at 45 minutes on Hobby and 24 hours on Pro and Enterprise plans, though persistent sandboxes resume into fresh sessions. Only the filesystem survives a stop; running processes must be restarted on resume, and exposed-port traffic is billable.

How do I keep secrets out of a sandbox running untrusted code?

Use a networkPolicy allow-list with a transform rule that injects the authorization header at the egress firewall. The VM can reach only the allowed domain and never holds the credential; add subnet deny rules to block non-TLS egress.