Skip to content
Docs

Update network policy

POSThttps://api.vercel.com/v2/sandboxes/sessions/{sessionId}/network-policy
Replaces 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

sessionIdstringRequired
The unique identifier of the session to update the network policy for.
teamIdstringOptional
The Team identifier to perform the request on behalf of.
slugstringOptional
The Team slug to perform the request on behalf of.
application/json
modestringRequired
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.
allowedDomainsarrayOptional
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).
allowedCIDRsarrayOptional
List of IP address ranges (in CIDR notation) the sandbox is allowed to connect to. Traffic to these addresses bypasses domain-based restrictions.
deniedCIDRsarrayOptional
List of IP address ranges (in CIDR notation) the sandbox is blocked from connecting to. These rules take precedence over all allowed rules.
injectionRulesarrayOptional
HTTP header injection rules for outgoing requests matching specific domains. Traffic to matching domains will be intercepted instead of proxied through encrypted connections.
200The session network policy was updated successfully.
sessionobjectRequired
This object contains information related to a Vercel Sandbox Session. v2 endpoints return "session" instead of "sandbox" as the response wrapper key.
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