Using Secure Compute with Sandbox
Attaching a Vercel Sandbox to a Secure Compute network allows you to route its traffic through your team's dedicated network. Its public-internet traffic then exits through the network's static IPs, which allows it to reach private resources in your own VPC over VPC peering. To learn how Secure Compute networks work, see the Secure Compute docs.
- The Sandbox CLI, the JavaScript SDK, or the Python SDK installed and authenticated.
- An existing Secure Compute network. If your team doesn't have one, create a network first.
To attach a sandbox to a Secure Compute network as you create it, supply the network's Network ID. To find your ID, from your Vercel dashboard, go to your team's Settings >Networking section. Then select Networking, and select the network you want to use. The Network ID appears in the top-left corner of the page, below the network name.
The sandbox starts attached to the selected network. To confirm the sandbox's public-internet traffic exits through it, run a command that queries a public IP echo service, which reports the network static IP that the request came from:
import { Sandbox } from '@vercel/sandbox';
const sandbox = await Sandbox.create({
name: 'my-sandbox',
networkId: '3k9x7m2p5q8w1z4n',
});
const result = await sandbox.runCommand({
cmd: 'curl',
args: ['-s', 'https://checkip.amazonaws.com/'],
});
console.log((await result.stdout()).trim()); // One of the network's static IPs
The printed address is one of the network's two static IPs, listed in the network's detail page in Settings > Networking. Seeing one of those IPs confirms the sandbox is attached to the Secure Compute network.
You can also attach an existing sandbox to a network, or switch it to another network, with update. Unlike setting networkId at creation, the change takes effect on the sandbox's next session: a running session keeps its existing network until it stops. Update the network, then stop the sandbox to apply it.
On a persistent sandbox (the default), the next SDK call auto-resumes the sandbox into a new session. Therefore, you don't need to start it explicitly. The runCommand or run_process call below resumes the sandbox on the new network and prints its network static IP:
import { Sandbox } from '@vercel/sandbox';
const sandbox = await Sandbox.get({ name: 'my-sandbox' });
await sandbox.update({ networkId: '3k9x7m2p5q8w1z4n' });
await sandbox.stop();
// The next command auto-resumes the sandbox into a new session with the new network
const result = await sandbox.runCommand({
cmd: 'curl',
args: ['-s', 'https://checkip.amazonaws.com/'],
});
console.log((await result.stdout()).trim()); // Now one of the new network's static IPs
When you no longer need the network, detach the sandbox by clearing its network assignment (null in TypeScript, None in Python, none in the CLI). Detaching works like attaching: the change takes effect on the next session, so stop the sandbox, then resume it.
import { Sandbox } from '@vercel/sandbox';
const sandbox = await Sandbox.get({ name: 'my-sandbox' });
await sandbox.update({ networkId: null });
await sandbox.stop();
// The next command auto-resumes the sandbox without the Secure Compute network
const result = await sandbox.runCommand({
cmd: 'curl',
args: ['-s', 'https://checkip.amazonaws.com/'],
});
console.log((await result.stdout()).trim()); // A Vercel infrastructure IP, not a network static IP
After detaching, the printed address is a Vercel infrastructure IP instead of one of the network's static IPs, confirming the sandbox is no longer attached to the Secure Compute network.
When a sandbox is attached to Secure Compute, traffic that leaves the private network via the public internet is billed as Private Data Transfer.
Traffic sent over VPC peering with your AWS environment does not incur data transfer charges.
See Secure Compute pricing for current rates and usage monitoring.
Was this helpful?