Skip to main content
Daytona sandboxes are temporary, isolated environments you create from code to run an agent. The sandboxed agent runs commands that a prompt can influence, so any API key you give the sandbox can leak through a prompt injection. With Agent Vault, there are no API keys within the agent’s environment. Each run uses two sandboxes: one that runs an Agent Vault proxy, and one linked sandbox that runs the agent. Daytona connects linked sandboxes over a private network. The agent’s sandbox can only connect to the proxy, so every request the agent makes goes through the proxy, and the proxy attaches the real credential to requests for the APIs you allowed. For each run, your code does the following:
  1. Creates an Agent Vault session for the run
  2. Creates a sandbox for the proxy, and starts the proxy in it
  3. Creates a sandbox for the agent, linked to the proxy’s sandbox, that can only connect to the proxy
  4. Starts the agent with the session token
  5. Stops the proxy when the agent finishes, so the proxy uploads the rest of the session logs
  6. Revokes the session and deletes the proxy’s sandbox, which also deletes the agent’s sandbox
Every proxy starts from the same proxy token, so you set up the proxy once, no matter how many sandboxes you run.
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

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.
To use a machine identity that already exists in your organization, select the Assign Existing tab instead.
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 token
  • INFISICAL_UNIVERSAL_AUTH_CLIENT_ID and INFISICAL_UNIVERSAL_AUTH_CLIENT_SECRET: the machine identity’s client ID and client secret
Your code passes the proxy token only to the proxy’s sandbox, and never passes the machine identity’s credentials to a sandbox. The agent’s sandbox can’t read the environment or files of the proxy’s sandbox.

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> with 0.44.7 or 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 SNAPSHOT to 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:
For more about creating sessions from code, see Create sessions with the API. For the flags the agent starts with, see the 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:
Claude Code replies, even though its sandbox has no Anthropic API key and can only connect to the proxy.
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.
To check which requests the agent made, view the session’s logs in Agent Vault. Requests that got a credential have the outcome Brokered.

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 update INFISICAL_AGENT_VAULT_PROXY_TOKEN where your code runs.

Troubleshooting

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_TOKEN has the current proxy token (a token stops working when you rotate it)
  • If you use EU Cloud or self-host Infisical, INFISICAL_URL in your code is the URL of your instance
  • The snapshot has an Infisical CLI version that can start a proxy from a proxy token
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.
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.