Update network policy
POST
https://api.vercel.com/v2/sandboxes/sessions/{sessionId}/network-policyReplaces the network access policy of a running session. Use this to control which external hosts the session can communicate with. This is a full replacement. Any previously configured network rules will be overwritten.
https://api.vercel.com/v2/sandboxes/sessions/{sessionId}/network-policy
const response = await fetch('https://api.vercel.com/v2/sandboxes/sessions/sessionId/network-policy?teamId=string&slug=string', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'Content-Type': 'application/json', }, body: JSON.stringify({ "mode": "custom", "allowedDomains": [], "allowedCIDRs": [], "deniedCIDRs": [], "injectionRules": [ { "domain": "string", "headers": "value", "match": { "path": { "exact": "string", "startsWith": "string" }, "method": [], "queryString": [ { "key": { "exact": "string", "startsWith": "string" }, "value": { "exact": "string", "startsWith": "string" } } ], "headers": [ { "key": { "exact": "string", "startsWith": "string" }, "value": { "exact": "string", "startsWith": "string" } } ] } } ] }),});
const data = await response.json();console.log(data);Response
{ "session": { "abortedAt": "1750344501629", "activeCpuDurationMs": "42", "architecture": "amd64", "createdAt": "1750344501629", "cwd": "/vercel/sandbox", "duration": "3600000", "id": "sbx_123a6c5209bc3778245d011443644c8d27dc2c50", "memory": "2048", "networkPolicy": { "allowedCIDRs": [], "allowedDomains": [], "deniedCIDRs": [], "injectionRules": [ { "domain": "api.vercel.com", "headerNames": [] } ], "mode": "custom" }, "networkTransfer": { "egress": "123", "ingress": "123" }, "projectId": "prj_123a6c5209bc3778245d011443644c8d27dc2c50", "region": "iad1", "requestedAt": "1750344501629", "requestedStopAt": "1750344501629", "runtime": "node22", "snapshottedAt": "1750344501629", "sourceSandboxName": "my-sandbox", "sourceSnapshotId": "snap_123a6c5209bc3778245d011443644c8d27dc2c50", "startedAt": "1750344501629", "status": "running", "stoppedAt": "1750344501629", "timeout": "3600000", "updatedAt": "1750344501629", "v0": "false", "vcpus": "2" }}AuthorizationbearerToken
Default authentication mechanism
application/json
The network access policy mode. Use "allow-all" to permit all outbound traffic. Use "deny-all" to block all outbound traffic. Use "custom" to specify explicit allow/deny rules.
List of domain names the sandbox is allowed to connect to. Only applies when mode is "custom". Supports wildcard patterns (e.g., "*.example.com" matches all subdomains).
List of IP address ranges (in CIDR notation) the sandbox is allowed to connect to. Traffic to these addresses bypasses domain-based restrictions.
List of IP address ranges (in CIDR notation) the sandbox is blocked from connecting to. These rules take precedence over all allowed rules.
400One of the provided values in the request body is invalid.
One of the provided values in the request query is invalid.
401The request is not authorized.
403You do not have permission to access this resource.
404Error
410Error
422Error
429Error
500Error