Restrict a robot token to specific IP addresses
Add an IP allowlist to a project or organization robot token so it only works from your IP addresses, in Manage or with the Access API.
An IP allowlist limits where a robot token works. Sanity refuses requests made with the token from any IP address that isn't on the list, so a leaked token can't be used outside your network.
This guide shows how to add, change, and remove an IP allowlist on a project or organization robot token, in Manage or with the Access API.
This is a paid feature
This feature is available on certain Enterprise plans. Talk to sales to learn more.
Prerequisites:
- An organization on an Enterprise plan that includes IP allowlists for tokens. Without it, saving an allowlist fails with
Robot network policies are not available for this organization. - Permission to create API tokens in the project or organization, such as the Administrator or Developer role. For more about tokens, see Authentication and tokens.
- The public IPv4 addresses your requests come from. These are the egress addresses of your servers, NAT gateway, or CI runners, not their private network addresses.
Choose the addresses to allow
An allowlist holds up to 10 entries. Each entry is a single IPv4 address, such as 34.120.10.5, or a range in CIDR notation, such as 34.121.0.0/24.
Sanity checks each entry when you save the allowlist:
- Ranges must be
/16or narrower. - Private and special-use ranges, such as
10.0.0.0/8or192.168.0.0/16, aren't accepted. Requests to Sanity never come from them. - IPv6 addresses aren't accepted. The Sanity API only accepts IPv4 connections, so your requests always reach it from an IPv4 address.
- Hostnames and wildcards, such as
example.comor34.120.*.*, aren't accepted. Use CIDR notation instead, such as34.120.0.0/16.
Allow every address your requests come from
If your requests leave your network through more than one address, for example several NAT gateways or a pool of CI runners, add all of them. Requests from an address that isn't on the list are refused.
Add an IP allowlist in Manage
To add an IP allowlist to an existing token:
- Open the token list. For a project token, open your project in Manage and go to Settings > API > Tokens. For an organization token, open your organization and go to API > Tokens.
- Open the token's three-dot menu and select Add IP allowlist.
- Enter an IP address or range. To add another entry, click Add range.
- Click Add allowlist.
The token now shows an IP allowlist badge in the token list. To see the allowed addresses, hover over the badge.
To restrict a new token, fill in the optional IP allowlist field when you create the token with Add API token.
Tokens used by a Sanity Function don't show Add IP allowlist. To learn why, see Limitations.
Add an IP allowlist with the Access API
API version requirement
Restricting robot tokens to specific IP addresses with the Access API requires API version 2027-07-11
To create a robot token with an IP allowlist, set networkPolicy.allowedSourceCidrs in the request body:
curl -X POST \
"https://api.sanity.io/v2025-07-11/access/project/<your-project-id>/robots" \
-H "Authorization: Bearer $SANITY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"label": "build-pipeline",
"memberships": [{
"resourceType": "project",
"resourceId": "<your-project-id>",
"roleNames": ["viewer"]
}],
"networkPolicy": {
"allowedSourceCidrs": ["34.120.10.5", "34.121.0.0/24"]
}
}'To add an IP allowlist to an existing robot token, send a PUT to the robot's endpoint:
curl -X PUT \
"https://api.sanity.io/v2025-07-11/access/project/<your-project-id>/robots/ROBOT_ID" \
-H "Authorization: Bearer $SANITY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"networkPolicy": {"allowedSourceCidrs": ["34.120.10.5", "34.121.0.0/24"]}}'Replace the placeholders:
<your-project-id>: your project ID. For an organization token, replaceproject/<your-project-id>in the URL withorganization/YOUR_ORGANIZATION_ID.ROBOT_ID: the robot'sid, returned when you create the robot and byGET .../robots.$SANITY_TOKEN: an environment variable holding a token that can create API tokens in the project or organization.
The response includes the saved allowlist in networkPolicy. Sanity normalizes the entries: single addresses get a /32 suffix, and duplicates are removed. This excerpt shows the field:
{
"networkPolicy": {
"allowedSourceCidrs": ["34.120.10.5/32", "34.121.0.0/24"]
}
}GET .../robots and GET .../robots/ROBOT_ID return the same field. For a token without an allowlist, networkPolicy is null. For the full request and response schemas, see the Access API reference.
Change or remove an IP allowlist
In Manage, open the token's three-dot menu:
- To change the addresses, select Edit IP allowlist, update the entries, and click Update allowlist.
- To lift the restriction, select Remove IP allowlist and click Remove allowlist. The token then works from any IP address.
With the Access API, send a PUT to the robot's endpoint. The list you send replaces the current list. To remove the allowlist, set networkPolicy to null:
curl -X PUT \
"https://api.sanity.io/v2025-07-11/access/project/<your-project-id>/robots/ROBOT_ID" \
-H "Authorization: Bearer $SANITY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"networkPolicy": null}'An empty allowedSourceCidrs list is rejected. Use null to remove the allowlist.
Changes take effect within about 30 seconds. Adding, changing, or removing an allowlist is recorded in your activity log.
A robot token can't set, change, or remove its own allowlist. A request made with the restricted token itself fails with A robot can't change its own network policy. Use your own account or a different token.
Limitations
An IP allowlist applies to requests made with the token itself. Keep these limits in mind before you add one:
- API CDN: A token with an allowlist works only with the API (
api.sanity.io), not the API CDN (apicdn.sanity.io). In@sanity/client, setuseCdn: false. - Sanity Functions: You can't add an allowlist to a token that a Sanity Function uses. Functions call the API from Sanity's IP addresses, so the allowlist would block them. The Access API rejects it with
Network policies are not supported on tokens managed by Sanity Functions. - Other Sanity-hosted services: Services that call the API with your token from Sanity's infrastructure, such as Context MCP and the Sanity MCP server, are refused. Give those services a separate token without an allowlist.
- Open connections: Listeners, Live Content API connections, and exports are checked when they connect. A connection that's already open when you change the allowlist keeps running until it closes.
- Tokens the robot creates: The allowlist applies only to this token. If the token can create API tokens, the tokens it creates don't inherit the allowlist.
- Other ways to create tokens: Set allowlists in Manage or with the Access API robots endpoints. The older project tokens endpoints and the
sanity tokensCLI command don't support them.
Fix requests refused by an IP allowlist
The allowlist only restricts the robot token. You can always sign in to Manage with your own account to change or remove it, from any address.
This token is not allowed from this IP address
The API returns HTTP 403 with the message This token is not allowed from this IP address. The request came from an address that isn't on the token's allowlist.
Find the public IPv4 address your requests come from and add it to the allowlist. If an integration is locked out and you can't find the address quickly, remove the allowlist to restore access. Then add it again with the right addresses.
Restricted robots must use api.sanity.io
The API returns HTTP 403 with the message Restricted robots must use api.sanity.io. The request went to the API CDN, which doesn't accept tokens with an allowlist. Turn off the CDN in your client configuration:
import {createClient} from '@sanity/client'
export const client = createClient({
projectId: '<your-project-id>',
dataset: 'production',
apiVersion: '2026-11-23',
useCdn: false,
token: process.env.SANITY_API_TOKEN,
})Run this client on a server only. Never ship a token in browser code. For more, see Keeping your data safe.
Service temporarily unavailable [robot-network-policy]
The API returns HTTP 503 with the message Service temporarily unavailable [robot-network-policy]. Sanity couldn't check the request against the allowlist. Retry the request with backoff. If the error continues, contact Sanity support.
Errors when you save an allowlist
Manage and the Access API reject an allowlist on the first invalid entry and name it in the message. ENTRY stands for the entry you sent:
ENTRY is too wide. Ranges must be /16 or narrower.: Split the range into narrower ranges.ENTRY is a private or special-use range. Requests to Sanity never come from it; use the public address range instead.: Use the public address your network uses to reach the internet.ENTRY is an IPv6 range. Sanity's API only accepts IPv4 connections, so requests never come from it. Use the IPv4 addresses your requests come from.: Replace it with your public IPv4 address.A network policy can have at most 10 CIDR ranges, got 11: Combine addresses into ranges, or remove entries you don't need.Robot network policies are not available for this organization: Your plan doesn't include IP allowlists. Contact Sanity sales.
Next steps
- Authentication and tokens: create robot tokens, set expiry dates, and rotate tokens.
- Keeping your data safe: other ways to protect your tokens.
- Access API reference: the full robots endpoints.
Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?