cd /news/ai-agents/your-agent-should-never-see-your-cre… · home › topics › ai-agents › article
[ARTICLE · art-176391] src=polylane.com ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Your agent should never see your credentials

Polylane detailed an architecture in which its agents never receive the API keys, OAuth tokens or OIDC workload-identity credentials used to reach customer infrastructure: tool code decrypts credentials in a Cloudflare Durable Object thread, sends authenticated requests through dedicated provider Workers such as a Datadog Worker, and returns only data to the model. The company blocks credential-bearing endpoints such as Neon's GET /projects/{id}/connection_uri, which can return a database URI containing the role's password, filters known secret fields like secret_token and password from responses, and sets redirect: "manual" on its PostHog client to stop tokens leaking through redirects. Model-written JavaScript runs in fresh isolates via Cloudflare's Worker Loader with globalOutbound: null, disabling direct network access so the code can only reach tools.

recommendation

Run model-written tool code in fresh isolates with globalOutbound: null, block credential-returning API routes, filter secret fields from responses, and set redirect: "manual" so tokens are never forwarded to another host.

more in playbook: Securing agents and AI tools
by read7 min views1 publishedNov 25, 2026
Your agent should never see your credentials
Image: source

Explore with AI #

What happens when a read-only API call returns a password? Neon’s GET /projects/{id}/connection_uri can return a database URI that includes the role’s password. The request changes nothing. If we pass that response to the model, we have still handed it a credential.

At Polylane, our agents need direct access to thousands of customers’ infrastructure to investigate issues and fix what breaks. That means managing API keys, OAuth tokens and OIDC-based workload identity federation across dozens of providers. We built our systems so agents get the data they need without being able to read the credentials behind it. Our tool code authenticates. The model, and the code it writes, never gets the credentials.

This post follows one request through that boundary: where the credential enters, what comes back, what the model’s own code can reach, and what happens when the model asks for something it shouldn’t.

The model asks, our tools authenticate #

Take our Datadog integration. The agent chooses a query and a time range. Our tools attach the credentials, send the request and return the metrics:

graph TB M["Model"] -->|"Metric query"| T["Polylane tools<br/>hold the credentials"] T -->|"Query + credentials"| D["Datadog API"] D -->|"Metric data"| T T -->|"Metric data"| M style T fill:#d1fae5,stroke:#6ee7b7,color:#065f46

The request starts in a thread, the Cloudflare Durable Object that runs the conversation. The thread loads the connected account from the workspace’s storage, where the API key and application key are encrypted. Our tool code asks the encryption service to decrypt them, then passes them with the query to a dedicated Datadog Worker. That Worker calls Datadog and returns the result.

The thread, the encryption service and the Datadog Worker all handle usable credentials, so we still have to trust that code. This separation keeps the key out of the conversation. It does not control what the API sends back.

A read can return a secret #

The Neon tool refuses credential routes before it sends the request. That covers connection strings, API keys and password routes. We check the decoded path, so api%5Fkeys hits the same rule as api_keys. Our incident.io proxy refuses GET /v2/alert_sources/{id} for a similar reason: it can return the alert source’s ingest token. Our internal code can still call these endpoints when it sets up an integration or queries a database.

We also filter known secret fields out of responses. The incident.io filter replaces fields such as secret_token and password, including inside nested objects. We maintain that list as providers change their APIs. It will not catch an arbitrary secret in a log line or a pasted message. It protects the credentials we use to connect an integration, and nothing more.

Redirects are the other way a credential can leave. In Cloudflare Workers, a request that follows a redirect can forward its headers to another host, including the Authorization header. Our PostHog client sets redirect: "manual" and rejects redirects. Otherwise we could validate the original destination and still send the token somewhere else.

The model writes code, too #

Most of our agent’s tool calls happen through code mode. The model writes a small JavaScript program that calls tools and works through their results. Keeping a key out of the prompt achieves little if that program can read it from the process it runs in.

Each script runs in a fresh isolate created with Cloudflare’s Worker :

const executor = new DynamicWorkerExecutor({
  : env.,
  timeout: EXECUTION_TIMEOUT_MS,
  globalOutbound: null,
});

globalOutbound: null disables direct network access. The script gets a tools object. Each function sends the tool name and inputs over RPC to code outside the isolate, which holds the credentials, makes the call and returns the result. The script can use that result. It has no provider configuration and no binding to the encryption service.

This also means the Neon rule holds inside scripts. A blocked endpoint does not become acceptable because the model wrapped it in JavaScript.

Shell access follows the same pattern. The agent edits files in our shared memory repository, but a separate sync sandbox runs the authenticated Git commands. It checks the changes before pushing and passes a five-minute write token only to the commands that need it. The agent’s shell never sees that token.

Someone still has to hold the key #

We encrypt stored credential fields with AES-GCM. The encryption service holds the key, and code that needs a credential calls it through a Cloudflare service binding.

Two details matter here:

  • Plaintext cache. The service keeps decrypted values in a separate KV namespace for 120 seconds, so tools can reuse a credential without decrypting it again. The cache key is a hash of the ciphertext, but the value is the usable credential, and we protect it that way. Generated scripts have no binding to it.
  • Shared key. We use one encryption key per environment, shared across workspaces. Encryption does not give each customer a separate cryptographic boundary. Access to the service and its cache matters as much as access to the stored records.

Encryption also needs maintenance. Each new integration needs a decision about which fields to encrypt and which to strip from connection records returned to clients. Those are separate code paths, and a switch that handles every provider type does not prove we covered every secret field. We have also seen an update encrypt a value that was already encrypted. The next decryption returned more ciphertext, which was useless as an API token. Stored values now carry an encv1: prefix, so the service recognizes them and skips a second pass.

Prefer tokens that expire #

A two-minute cache is not a two-minute credential. When the entry expires, the provider’s API key still works, and copies can remain in request or thread memory.

Where a provider supports short-lived tokens, we use them. Our Google Cloud integration exchanges a Polylane identity for a reader token with a requested lifetime of 15 minutes, so we never hold a customer service-account key. For PostHog OAuth, the connection’s Durable Object handles refresh and stores the new tokens encrypted. The tool receives the access token, and the refresh token stays with the code that renews it.

A stolen short-lived token eventually stops working. Until then, it can do whatever its permissions allow.

The agent can still ask for the wrong thing #

An agent does not need to steal a token to misuse it. If the tools run any request the agent asks for, keeping the token away from the model does not stop a destructive call. Providers do not always help here. A Depot organization token, for example, has no vendor scopes, so our code has to enforce the restrictions.

When a person asks Polylane to change a provider resource in the console, we check the caller’s and account’s permissions, then send the proposed write to a safety model for review. If it passes, we show the person the exact operation and inputs and wait for confirmation:

graph TB A["Check caller and<br/>account permissions"] --> B["Review the proposed write"] B --> C["Person confirms<br/>the exact operation"] C --> D["Execute the approved call"]

A failed check stops the call. So does missing confirmation, whether it is unavailable, declined or still pending.

This is also why code-mode scripts cannot make provider writes during interactive turns. A change buried inside a script is hard for a person to inspect. We require a separate tool call so they can approve the operation and its inputs before it runs. Scheduled investigations can only read from connected provider APIs, though they can still edit local files and prepare a pull request.

Start with one request #

If you are building an agent with production access, pick one of its tools and follow a request through your code. Find where the credential enters and where it becomes readable. Then follow the response back, including errors and redirects. The Neon example is easy to miss if you stop at the request headers.

Repeat that for a script the model writes and for a command it can run in a shell. You should be able to point to the code that attaches the credential, the checks that restrict its use and the data the model gets back. If the boundary depends on the model choosing not to read or reveal a token it already has, move the token.

── more in #ai-agents 4 stories · sorted by recency
── more on @polylane 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/your-agent-should-ne…] indexed:0 read:7min 2026-11-25 · —