Skip to main content

Overview

Agents in a Daytona sandbox often need API keys. Prompt-injected code can read a key from the sandbox and send it anywhere. With Formal, the key never enters the agent’s sandbox. Each run uses two linked sandboxes:
  1. An Endpoint sandbox runs the headless . It logs in with a Formal machine user API key.
  2. An agent sandbox is linked to it. Its network allow list contains only the Endpoint sandbox, and its HTTP clients use it as HTTPS_PROXY.
  3. A network rule forwards requests for the API hostname to a .
  4. A on the Connector adds the API key. and logs apply to every request.
The agent keeps calling the real API hostname, such as api.stripe.com.
This guide uses the Stripe API with a bearer key. The same setup works for any HTTP API and every Native User type.

Machine user API key

The Endpoint logs in with FORMAL_API_KEY. The key lives only in the Endpoint sandbox, which the agent cannot read. To scope it:
  • Create a dedicated machine user and API key for Daytona.
  • Pass the key from your orchestrator when you create the sandbox. Never bake it into a snapshot.
  • Rotate the key on a schedule.

Daytona features used

Sandbox-level network settings are available to Daytona organizations on Tier 3 or 4.

Steps

1. Store the key on the Connector

Set STRIPE_API_KEY in the Connector’s environment. Remove the key from any Daytona secret or snapshot that the agent can use.

2. Create the resource, Native User, and listener

Verify: stripe appears under the Connector’s Reachable Resources.

3. Create the machine user and API key

  1. Go to Users, click Create User, and choose Machine. Name it daytona-agents.
  2. Create an API key for it. Store it in your orchestrator as FORMAL_DAYTONA_API_KEY.
Copy the machine user’s user_... ID for the next step.

4. Forward API traffic to the Connector

Linux Endpoints ignore pre_tcp, so pre_tls checks the hostname and user.

5. Create the Endpoint snapshot

Copy the Ubuntu/Debian (x86, headless) package link from the Control Plane (Download > Linux).
Verify: formal-endpoint appears in the Daytona dashboard under Snapshots with the Active state.

6. Run an agent

The link network address appears on eth1 shortly after the agent sandbox is linked. Run your agent with the same env as the curl command. Verify: the script prints a Stripe JSON response.

7. Verify the key stays out

Run these in the agent sandbox, with the env from step 6:
In Logs, each request shows the daytona-agents machine user and the stripe resource.

Operational notes

  • Set HTTPS_PROXY and HTTP_PROXY for your agent’s tools, as in step 6. The agent sandbox has no other route out.
  • Create linked agent sandboxes with auto_delete_interval=0.

Next Steps

Modal

The same pattern with a Modal Sidecar and OIDC

E2B

The same pattern with the Endpoint in an E2B sandbox