Overview
Agent Gateways let your agents call LLM APIs like Anthropic and OpenAI without ever seeing your API keys. Your real credentials stay secure on Runloop’s servers—the agent only gets a temporary gateway token. Example: using Claude Code with a gateway When you create a devbox with a gateway configuration, Runloop sets environment variables like$ANTHROPIC_URL and $ANTHROPIC inside the devbox. Any LLM client can use them. For example, to run Claude Code inside the devbox with the gateway:
sk-ant-... key. Even printing all environment variables only reveals useless gateway tokens:
x-api-key: sk-ant-... but your agent never sees it.
This protects your API keys from:
- Prompt injection attacks — Even if an attacker tricks your agent into printing all environment variables, they only get useless gateway tokens
- Malicious code — Code running in the devbox cannot access your real credentials
- End users — Users of your AI product cannot extract your API keys through social engineering
How It Works
- Configure a Gateway: Define the target endpoint (e.g.,
https://api.anthropic.com) and how credentials should be applied - Store the Secret: Create an account secret containing your actual API key
- Launch with Gateway: Create a devbox with the gateway configuration—it receives a gateway URL and token, not your real API key
- Make Requests: Your agent uses the gateway URL and token to make API calls; the gateway injects your real credentials server-side
Why Use Agent Gateways?
Credential Isolation
The most important benefit is that your API keys never enter the devbox. The agent only sees:- A gateway URL (e.g.,
$ANTHROPIC_URL) - A gateway token (e.g.,
$ANTHROPIC)
Defense Against Prompt Injection
Sophisticated prompt injection attacks try to manipulate AI agents into revealing secrets. With Agent Gateways:Quick Start: Setting Up a Gateway for Anthropic
This example shows how to create a gateway config for the Anthropic API, store your API key as a secret, and use them together in a devbox.Step 1: Create a Gateway Config
First, create a gateway config that defines the target endpoint and authentication mechanism.Step 2: Create a Secret for Your API Key
Store your LLM provider API key as an account secret. Use thesecret_name defined in Step 1.
Step 3: Create a Devbox with the Gateway
Create a devbox using your gateway config and secret. Thesecret field must match the name of the secret you created in Step 2.
Step 4: Use the Gateway in Your Agent
When you create a devbox with a gateway configuration, Runloop automatically sets environment variables on the devbox:$ANTHROPIC_URL— The gateway endpoint URL$ANTHROPIC— A gateway token (not your real API key)
Gateway Configuration Options
Authentication Mechanisms
Gateway configs support three authentication types:Custom Headers
Some APIs require more than one credential header. In addition to the auth mechanism, a gateway config can carry up to 8custom_headers, applied to every proxied request after the primary credential. Each entry pairs a header name with exactly one of:
secret— an account secret name orsec_ID. The value is resolved server-side at devbox launch and never exposed to the devbox; config reads return thesec_ID.value— a literal string.
DD-API-KEY and DD-APPLICATION-KEY:
- At most 8 entries per config; names must be valid header tokens and unique (case-insensitive).
Authorizationis reserved for the primary credential. Structural headers (Host,Content-Length, hop-by-hop headers,Upgrade),Runloop-Gateway, and a name colliding with the auth mechanism’skeyare also rejected.- A custom header replaces any header of the same name sent from the devbox.
- On update, omitting
custom_headerskeeps the current list; passing[]clears it. The list is always replaced wholesale. - Config changes take effect the next time a devbox is launched or resumed with the config; running devboxes are unaffected.
Common Gateway Configurations
OpenAI Gateway
Custom API Gateway
Private Package Index Gateway
Package managers like pip and uv authenticate to package indexes with HTTP Basic credentials. Put the gateway token in the password position of the index URL — the username is arbitrary.Credentials embedded in the index URL are sent preemptively, which the gateway requires. Clients that wait for a
401 challenge before sending credentials (e.g. keyring-backed auth) are not supported.Multiple Gateways
You can configure multiple gateways for a single devbox, allowing your agent to securely access multiple APIs.Managing Gateway Configs
List Gateway Configs
Update a Gateway Config
Delete a Gateway Config
Using Agent Gateways with LLM Clients
Most LLM client libraries and tools support custom base URLs. Set them to your gateway environment variables.Claude Code
OpenAI SDK
Codex (OpenAI)
Codex supports custom API base URLs via environment variables. Set up an OpenAI gateway and configure the devbox:OpenCode
OpenCode supports multiple LLM providers. Configure a gateway for your preferred provider:Gemini CLI
Gemini CLI authenticates with a Gemini API key or Vertex AI credentials. Set up a Google AI gateway:DeepAgents
DeepAgents supports multiple LLM providers. Configure gateways for the providers you need:Security Best Practices
1. Prefer Agent Gateways Over Direct Secrets
For any sensitive API credentials—especially LLM provider keys—use Agent Gateways instead of passing secrets directly to devboxes. Gateways ensure your real API keys are never exposed to the agent, protecting against prompt injection, credential leaks, and malicious code. Avoid:- Passing API keys directly to devboxes via the
secretsparameter - Hardcoding API keys in code that runs inside devboxes
- Storing API keys in files within devboxes
2. Combine with Network Policies
For maximum security, combine Agent Gateways with Network Policies to restrict which endpoints your devbox can reach. Setallow_agent_gateway to enable gateway traffic without opening up all of *.runloop.ai.
3. Use Descriptive Gateway Names
The gateway name becomes the prefix for environment variables. Use clear, uppercase names:- ✅
ANTHROPIC,OPENAI,INTERNAL_API - ❌
my-gateway,apiKey1,test
4. Rotate Secrets Regularly
Update your account secrets periodically. When you update a secret, all new devboxes using that secret will automatically use the new value.5. Monitor Gateway Usage
Review which gateways are being used and audit access patterns to detect potential misuse.Comparison: Agent Gateways vs. Direct Secrets
Common Use Cases
AI Coding Agent
Secure your coding agent that needs access to multiple LLM providers:Multi-Tenant AI Platform
When building an AI platform serving multiple customers, use gateways to isolate credentials. You can reuse the same gateway config with different secrets for each customer:Related Documentation
- MCP Hub — Give agents access to MCP tool servers (GitHub, Slack, etc.)
- Account Secrets — Managing secrets for your account
- Network Policies — Control network access for devboxes
- Agents API — Build AI agents with Runloop
