- Creates an Agent Vault session for the run
- Creates a sandbox for the proxy, and starts the proxy in it
- Creates a sandbox for the agent, linked to the proxy’s sandbox, that can only connect to the proxy
- Starts the agent with the session token
- Stops the proxy when the agent finishes, so the proxy uploads the rest of the session logs
- Revokes the session and deletes the proxy’s sandbox, which also deletes the agent’s sandbox
Why not run the same proxy for every sandbox?
Why not run the same proxy for every sandbox?
To reach one shared proxy, every agent sandbox would need internet access to the proxy, and the proxy would have to accept connections from the internet. Anyone who gets a session token could then use the proxy from anywhere until the session ends.Only sandboxes linked to the proxy’s sandbox can reach the proxy, so nothing outside the run can send requests through it.
Prerequisites
- The Admin role in Agent Vault
- A Daytona organization on Tier 3 or 4, because on Tiers 1 and 2 you can’t limit a sandbox to reaching the proxy, and the proxy can’t reach Infisical
- A Daytona API key in the
DAYTONA_API_KEYenvironment variable on the machine that runs your code - The Daytona SDK for your language: Python (with
requests), TypeScript, Go (withapi-client-go), Ruby, or Java (with Jackson) - The API keys your agent uses, such as your Anthropic API key
Step 1: Set up Agent Vault
Create an access bundle
Create an access bundle that holds a service for each API the agent calls.1
In Infisical, open Agent Vault from the product switcher and go to Access Bundles.
2
Select Create Access Bundle. Give the access bundle a Name, such as
sandbox-agent, then select Create Access Bundle.3
Select the access bundle you just created, then select Add Service.
4
On the Choose a template panel, pick the template for the API, such as Anthropic for Claude Code, or select Custom HTTP API.
5
On the Details step, check the hosts the service covers, or enter the API’s host if you selected Custom HTTP API, then select Continue.
6
On the Credential step, paste the real API key, then select Continue.
If the API expects the key somewhere other than a header, such as in the URL, add a substitution instead, and have the agent send the placeholder you enter in Replace.
7
On the Review step, select Add Service. Repeat from the third step for each remaining API.
Create a proxy
1
In Agent Vault, go to Proxies and select Create Proxy.
2
Enter a Name, such as
sandboxes, and expand Advanced Options. Under Traffic Policy, choose Access bundle hosts only. Then add any other hosts the agent needs to reach to Exceptions (for example, registry.npmjs.org).Make sure you select the Access bundle hosts only traffic policy. The proxy can reach the internet, so if you leave the traffic policy set to Any host, the agent can send requests through the proxy to any host.
3
Select Create, then copy the proxy token from the Proxy Token dialog. Infisical shows the token only once.
Create a machine identity for your code
Your code creates a session for each run as a machine identity. Give the machine identity the Member role and access to only this access bundle, because an Agent Vault admin can create sessions for every access bundle.1
In Agent Vault, go to Access Control > Machine Identities and select Add Machine Identity.
2
On the Create New tab, enter a Name, choose Member in Role, then select Create. Infisical creates the machine identity with Universal Auth and opens its page.
3
On the machine identity’s page, select Universal Auth under Authentication. Copy the Client ID, then select Add Client Secret and copy the client secret.
4
Go to Access Bundles and open the access bundle the agent uses. Select Options > Manage Access, then select Grant Access. Select the machine identity, then select Grant Access.
Step 2: Give your code the credentials
Set the following environment variables where the code that starts your sandboxes runs:INFISICAL_AGENT_VAULT_PROXY_TOKEN: the proxy tokenINFISICAL_UNIVERSAL_AUTH_CLIENT_IDandINFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET: the machine identity’s client ID and client secret
Step 3: Create the snapshot
Both sandboxes start from the same Daytona snapshot, which has the Infisical CLI and your agent. This function creates a snapshot with Claude Code installed the first time your code runs:- Infisical CLI: replace
<cli-version>with0.44.7or later, because earlier versions can’t start a proxy from a proxy token - Changing the image: the function reuses the snapshot if one with the same name exists, so after you change the image, change
SNAPSHOTto a new name
Step 4: Run an agent in a sandbox
This function runs one prompt in a new sandbox. Replace<access-bundle-name> at the top with your access bundle’s name. If you use EU Cloud or self-host Infisical, also replace https://app.infisical.com with the URL of your instance:
agent-vault run CLI reference.
To run a different agent, install it in the snapshot, replace the
claude command with the agent’s non-interactive command, such as codex exec, and replace the Claude Code settings in the agent’s environment variables.For an agent you built yourself, run it the same way, or set the proxy in its HTTP client.Step 5: Verify it works
Call the function with a prompt that needs an API in the access bundle:Each run now gets its own two sandboxes and its own session. The only credential in the agent’s sandbox is a session token, and your code revokes the session when the run ends.
Security considerations
Network access from the agent’s sandbox
The agent’s sandbox can only connect to the proxy’s address on the network between the two sandboxes. With the Access bundle hosts only traffic policy, the agent can reach two kinds of hosts through the proxy: the hosts of the services in the session’s access bundle, and the proxy’s exceptions.Compromised sandboxes
Each proxy’s sandbox holds a copy of the proxy token. If you think someone took control of a sandbox, rotate the proxy’s token, then updateINFISICAL_AGENT_VAULT_PROXY_TOKEN where your code runs.
Troubleshooting
The proxy doesn't start
The proxy doesn't start
The function’s error includes the proxy’s log. If the log says
The provided access token is malformed, the proxy token is wrong. Check the following:INFISICAL_AGENT_VAULT_PROXY_TOKENhas the current proxy token (a token stops working when you rotate it)- If you use EU Cloud or self-host Infisical,
INFISICAL_URLin your code is the URL of your instance - The snapshot has an Infisical CLI version that can start a proxy from a proxy token
Requests fail with a 403 partway through a run
Requests fail with a 403 partway through a run
The session expired or was revoked. Set the session’s
ttl a few minutes longer than the proxy sandbox’s time to live, so the session lasts as long as the sandboxes can run.Requests to a host fail with a 403 from the start
Requests to a host fail with a 403 from the start
The proxy’s traffic policy blocks hosts that no service in the access bundle covers. Add a service for the host, or add the host to the proxy’s exceptions.
Next steps
Create sessions with the API
Create a session for each agent run from your own code.
Session logs
Record every request an agent makes during a session.