Prerequisites
- An Infisical organization where you’re an Agent Vault admin
- The Infisical CLI installed on the machine that will run the proxy
- The API keys your agent uses, such as its model provider’s key
We recommend running the proxy on a different machine than the agent. If they run on the same machine, the agent could read the proxy’s state directory. That directory contains sensitive values,
like the proxy’s access token and the private key of its certificate authority.We also recommend keeping both machines on the same private network. This is because every request the agent makes goes through the proxy, and a round trip between networks adds latency to every request.
Step 1: Set up Agent Vault
Create an access bundle
First, create an access bundle that holds a service for each API your 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
my-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, or select Custom and enter the API’s host.
5
On the Credential step, paste the real API key.
If the API expects the key somewhere other than a header, such as in the URL, add a substitution instead. Note the placeholder you enter in Replace, because your agent sends it in Step 3.
6
Select Add Service. Repeat from the third step for each remaining API.
Enroll a proxy
Next, enroll a proxy. Every request your agent makes goes through the proxy, which attaches the real credential from the access bundle before forwarding the request to the API.1
Go to Proxies and select Create Proxy.
2
Give the proxy a Name, then select Create.
3
In the Enrollment Token dialog, copy the command from the CLI tab, or from the Docker or systemd tab to keep the proxy running after you close the terminal. The enrollment token expires in an hour.
4
Run the command on the machine that will run the proxy.
17323. Make sure the agent’s machine can reach that port, and note the proxy machine’s address.
Create a session
Finally, create a session. The session token is the only credential your agent has.1
Go to Sessions and select Create Session.
2
Pick the access bundle you created, set a duration under Expires, then select Create Session.
3
Copy the session token from the command in the dialog. It’s the value after
--session-token. The token appears once and can’t be retrieved again.Step 2: Download the proxy’s certificate
The proxy decrypts each HTTPS request to attach the credential, so the agent has to trust the proxy’s certificate authority. On the agent’s machine, download the certificate from the proxy:ca.pem where the agent can read it. The certificate isn’t secret, so you can add it to the agent’s container image. If you re-enroll the proxy, download the certificate again.
Step 3: Replace the API keys with placeholders
Delete the real API keys from the agent’s code and configuration. Most SDKs refuse to start without a key, so pass a placeholder value instead, such asagent-vault. The proxy replaces the placeholder with the real credential:
- If the service uses Bearer or Basic credentials: the proxy replaces the header that carries the key, so any placeholder works
- If the service uses a substitution: use the exact placeholder you entered in Step 1
Step 4: Send requests through the proxy
Set the proxy and the certificate in the agent’s HTTP client. The proxy URL has the session token as its password:- Environment variables
- Python
- Node.js
- Go
Most HTTP clients read the proxy and the certificate from environment variables, so if you set these variables for the agent’s process, you don’t need to change its code:Clients that read
SSL_CERT_FILE or REQUESTS_CA_BUNDLE trust only the certificates in that file. If the agent calls an HTTPS host in NO_PROXY, add your system’s certificates to ca.pem, such as with cat /etc/ssl/certs/ca-certificates.crt >> ca.pem on Debian or Ubuntu.The proxy only supports HTTP/1.1, so WebSocket connections and clients that only speak HTTP/2, such as gRPC clients, fail through the proxy. If an API offers both, configure the agent to use its plain HTTPS requests. Many SDKs fall back to HTTPS when a WebSocket connection fails.
Step 5: Verify it works
Make a request from the agent to an API in the session’s access bundle. For example, if the bundle has a GitHub service, requesthttps://api.github.com/user. GitHub returns the account that the service’s token belongs to, even though the agent doesn’t have a GitHub token.
If you’ve set up session logs, view the session’s logs to check which requests the agent made. Requests that got a credential have the outcome Brokered.
Your agent now calls APIs through the proxy. The only credential the agent has is the session token, and if you revoke the session, the proxy stops attaching credentials to the agent’s requests.
Replace the session token
The session token is part of the proxy URL, so when you give the agent a new session, create a new HTTP client with the new token. If the agent reads the environment variables, restart it with the new values. To replace sessions automatically, such as for a process that runs for days, create sessions with the API.Troubleshooting
Requests fail with a 407 from the proxy
Requests fail with a 407 from the proxy
For HTTPS requests, the client reports a failed tunnel, such as
CONNECT tunnel failed, response 407. The request reached the proxy without the session token. Check that the proxy URL includes x-agent-vault:<session-token>@.Requests fail with a 403 from the proxy
Requests fail with a 403 from the proxy
If the client reports a failed tunnel, such as
CONNECT tunnel failed, response 403 or Tunnel connection failed: 403 Forbidden, the session expired or was revoked. Create a new session and replace the session token.The API returns an authentication error
The API returns an authentication error
The request reached the API without the real credential. Check that a service in the session’s access bundle covers the host, and that the service’s credential is correct. If the service uses a substitution, check that the agent sends the exact placeholder in Replace.
Requests fail with a certificate error
Requests fail with a certificate error
The agent doesn’t trust the proxy’s certificate. Check that the client loads
ca.pem, and download the certificate again if you re-enrolled the proxy.Requests reach the API without the proxy
Requests reach the API without the proxy
If the API rejects the placeholder key and the request doesn’t appear in the session logs, the agent’s requests skip the proxy. Check that the host isn’t in
NO_PROXY, and that the HTTP client reads the proxy setting:- The built-in
fetchin Node.js ignoresHTTPS_PROXYunless you setNODE_USE_ENV_PROXY=1(Node.js 24 or later) - For a client that ignores
HTTPS_PROXY, set the proxy in code, as the examples in Step 4 show
Next steps
Create sessions with the API
Create a session for each agent run from your own code.
Services
Limit the methods and paths an agent can use, and replace placeholders with real values.