Use a Box API key for servers, CI jobs, Docker images, and hosted workers. API keys authenticate the Box CLI without an interactive browser flow.
Treat API keys as secrets. Store them in your platform secret manager and pass them at runtime as BOX_API_KEY. Do not commit them, print them in logs, or bake them into Docker images.
Create a key
- Open the Box dashboard.
- Go to API Keys.
- Create a key.
- Copy it immediately. The dashboard only shows the secret once.
Use the copied value as BOX_API_KEY in your runtime environment:
box login "$BOX_API_KEY" --json
That emits:
{
"event": "login_complete",
"data": {
"user": {
"login": "octocat",
"email": "octocat@example.com"
}
}
}
For scripts, prefer --json on login too. It keeps stdout machine-readable and makes failed auth return the standard JSON error line.
Store keys
Use the secret manager for your platform:
| Platform | Store as |
|---|
| Railway | Variable named BOX_API_KEY |
| GitHub Actions | Repository or environment secret named BOX_API_KEY |
| Docker Compose | Environment variable or secret named BOX_API_KEY |
| Kubernetes | Secret mounted or exposed as BOX_API_KEY |
Do not put API keys in:
- Dockerfiles
- Images
- Source code
- Shell history
- Public CI logs
Rotate a key
Rotating a key immediately revokes the old secret, preserves the API key id, and shows a new secret once.
Use Rotate only when you can update the deployed secret immediately:
- Rotate the key in the dashboard.
- Copy the new secret.
- Update
BOX_API_KEY in your platform secret manager.
- Redeploy or restart workers that use the key.
To avoid downtime, create a second key first:
- Create a new key.
- Update the platform secret to the new key.
- Redeploy or restart workers.
- Delete the old key after the new deployment is live.
Delete a key
Deleting a key immediately revokes it. Existing CLI configs or running processes using that key will fail the next Box API request with an auth error.
Delete keys that are unused, leaked, or no longer tied to an active deployment.
Use the key
For Docker and hosted workers, see Use in Docker.
For scripts and applications that wrap the CLI, see Use in Code.
For runtime secrets inside Boxes, see Secrets & Setup.