---
title: Sandbox Credentials
description: Give Vercel Sandbox access to private services with credentials Vercel sets up for you.
url: "https://vercel.com/docs/sandbox/concepts/credentials"
last_updated: 2018-10-20
related:
  - /docs/sandbox/concepts/firewall
  - /docs/environment-variables/shared-environment-variables
  - /docs/environment-variables
  - /docs/sandbox/concepts/authentication
  - /docs/deployments/environments
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest docs search "<query>"
search_kb_with_vercel_cli: npx vercel@latest kb search "<query>"
---

# Sandbox Credentials

Request a credential when you create a sandbox, and Vercel handles the rest using the credentials your project or team already has.

The credential stays outside the sandbox. The [sandbox firewall](/docs/sandbox/concepts/firewall) adds it to matching requests as they leave, so code in the sandbox, including an agent and the packages it installs, can use the credential but can't read it.

## Which credentials a sandbox can request

| Credential | Request it with | What it covers |
| --- | --- | --- |
| [npm](#npm-credentials) | `credentials: { npm: true }`, `credentials=SandboxManagedCredentials(npm=True)`, or `--credentials=npm` | Install packages from your project's or team's npm registries. |

## Where each credential applies

Each credential goes only to its own hosts. npm credentials, for example, go to the registries in the npm configuration Vercel finds for the sandbox, on the project or your team. Requests to other hosts leave the sandbox without credentials.

## npm credentials

Vercel configures the sandbox from the registry credentials in your project's or team's environment variables, including custom registries such as GitHub Packages or JFrog Artifactory, so a coding agent or build can run `npm install` on a repository with private dependencies.

If the sandbox's project or your team already has `NPM_TOKEN` or `NPM_RC` in one of the [places Vercel checks](#where-vercel-looks-for-npm-credentials), you don't need to set up anything else.

### Where Vercel looks for npm credentials

Vercel checks the sandbox's project first, then falls back to your team's [Shared Environment Variables](/docs/environment-variables/shared-environment-variables). It uses the first place that has `NPM_RC` or `NPM_TOKEN`:

| Order | Place | What Vercel reads |
| --- | --- | --- |
| 1 | The sandbox's project | The project's [Environment Variables](/docs/environment-variables) and the Shared Environment Variables linked to the project, in one environment. These are the variables a build of the project gets in that environment, except variables limited to a Git branch. |
| 2 | Your team, in Development | Your team's Shared Environment Variables, whether or not they're linked to a project. |
| 3 | Your team, in Preview | Your team's Shared Environment Variables, whether or not they're linked to a project. |

The team fallback never reads Production values.

The environment Vercel reads on the project depends on how the request [authenticates](/docs/sandbox/concepts/authentication):

| Request made with | Project environment |
| --- | --- |
| A project's OIDC token | The token's environment, which can be Development, Preview, Production, or a [custom environment](/docs/deployments/environments#custom-environments). |
| An access token, which the Sandbox CLI uses when it doesn't authenticate with a `VERCEL_OIDC_TOKEN` | Development. |

The lookup follows these rules:

- `NPM_RC` takes precedence over `NPM_TOKEN`. Vercel checks both on the project before your team, so a project's `NPM_TOKEN` wins over your team's `NPM_RC`.
- An empty `NPM_RC` or `NPM_TOKEN` turns npm credentials off, and Vercel doesn't fall back to the next place. To opt a project out of your team's credentials, set one of them to an empty value on the project.
- Sandboxes don't read `VERCEL_AGENT_NPM_RC` or `VERCEL_AGENT_NPM_TOKEN`. Those variables configure [Vercel Agent](/docs/agent/private-dependencies).

### Configure registry credentials

If neither the project nor your team has registry credentials yet, add them in one of these places:

- **For one project**: In the project's **Settings**, open **Environment Variables**. Add `NPM_TOKEN` or `NPM_RC` in each environment your sandboxes use, then save it.
- **For every project in your team**: In your team's **Settings**, open **Environment Variables**. Add `NPM_TOKEN` or `NPM_RC` as a Shared Environment Variable in **Development** or **Preview**, then save it. You don't need to link it to a project.

Use `NPM_TOKEN` for packages on `registry.npmjs.org`. Set it to an npm access token with read access to your private packages.

Use `NPM_RC` for a custom registry or several registries. Set it to the registry configuration from your `.npmrc`, and add each token it references in the same place and environment:

```ini filename="NPM_RC"
@acme:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}
```

Vercel resolves `${NAME}` references from the same place as the `NPM_RC` itself. An `NPM_RC` on the project reads the project's environment, and an `NPM_RC` on your team reads your team's Shared Environment Variables in the same environment.

### Create a sandbox with npm credentials

**terminal.sh**

```bash filename="terminal.sh"
sandbox create --credentials=npm
```

**index.ts**

```ts filename="index.ts"
import { Sandbox } from '@vercel/sandbox';

const sandbox = await Sandbox.create({ credentials: { npm: true } });
await sandbox.runCommand('npm', ['install']);
```

**main.py**

```py filename="main.py"
import asyncio

from vercel import sandbox


async def main() -> None:
    async with sandbox.create_sandbox(
        credentials=sandbox.SandboxManagedCredentials(npm=True),
    ) as box:
        await box.run_command("npm", ["install"], check=True)


asyncio.run(main())
```

The `--credentials` flag also works with `sandbox run` and `sandbox sh`. If Vercel finds no registry credentials for the sandbox, sandbox creation fails with a `400` error. An empty `NPM_RC` or `NPM_TOKEN` counts as no credentials.

### How npm credentials reach the registry

The sandbox gets an `.npmrc` with your registry URLs and scopes, and no tokens. The sandbox firewall adds the `Authorization` header to `GET` and `HEAD` requests to those registries.

Vercel looks up the registry configuration when a sandbox is created, when it resumes, and when its network policy changes, each time with the token that makes that request. A sandbox created with a Production OIDC token and later resumed with an access token switches to the project's Development credentials, or your team's. A rotated token reaches a running sandbox the next time it resumes.

### Limits

npm credentials have the following limits:

- They cover installs only. `npm publish` and other write requests leave the sandbox without credentials.
- They work with package managers that read `.npmrc`, including npm, pnpm, and Bun.
- They don't add registry hosts to your [network policy](/docs/sandbox/concepts/firewall#network-policies). If the policy is `deny-all`, or a user-defined policy that doesn't allow one of your registry hosts, sandbox creation fails with a `400` error.
- Project credentials aren't limited by environment. Anyone who can use a sandbox in the project can install the packages that sandbox's credentials can read, whatever environment their own token is for.
- Team credentials are team-wide, so anyone who can create a sandbox in the team can install the team's private packages.

## Search the docs from your terminal

Search the Vercel docs and read pages as Markdown with the Vercel CLI. No login required.

```bash
# Find docs pages by keyword
npx vercel@latest docs search "environment variables"
npx vercel@latest docs search "function timeout"

# Print a docs page as Markdown, by path or URL
npx vercel@latest docs inspect <page>
```

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```

---

[View full sitemap](/docs/sitemap)


If you encounter incorrect information, can’t find what you need, need a capability Vercel doesn’t currently offer, or have any other feedback to report, please do it by following the instructions at https://vercel.com/feedback.md.
