← All essays· Engineering

Let Your Agent Use Your Secrets Without Showing Them to the Model

OpenViking v0.5.7 adds Seal secrets to the gateway: the model provider receives a reference, while your tools still get the real value when they run.

Halfway through debugging, you paste a token straight into the chat and tell the agent to “try again with this.” We do it often enough ourselves. Few people stop to think, as they paste, that the string goes to the model provider along with the message, and that every request after it carries it again.

OpenViking Gateway is a proxy between your agent and the model provider. The agent sends its requests to the gateway, which adds memory and forwards them to the model. In v0.5.7 the gateway gained a switch called Seal secrets.

With the switch on, this is the same message on either side of the gateway. On top is what we typed into pi, an open-source command-line coding agent similar to Claude Code; below it is the version that leaves the gateway for the model.

What you typedclient → gateway
deploy.sh keeps returning 401. Try this new token against http://127.0.0.1:8787/whoami and see if it works: ghp_JY0g…
OpenViking Gateway · sealtoken swapped for a reference
What the model receivesgateway → model
deploy.sh keeps returning 401. Try this new token against http://127.0.0.1:8787/whoami and see if it works: {{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}
Recorded from a real request pi sent through OpenViking Gateway. The message was typed in Chinese and is translated here. The token is a randomly generated fake; only its first 8 characters are shown.

The token is the only thing that changed. It's a fake we generated at random for this test, and only its first 8 characters are shown here. 127.0.0.1:8787 is a test service we ran on our own machine, and it accepts this one token and nothing else. The model also receives a separate note telling it what the reference is and how to use it.

Where that string would have gone

Every request an agent makes carries the full conversation history. Paste a token once and it is resent on every turn after that. If the agent reads .env, or runs a command that echoes the secret, the copy in the tool output goes out too.

We recorded the traffic from this test on both sides of the gateway. Across three turns and 8 model requests, the token appeared 18 times in the request bodies the client sent to the gateway. Without sealing, all 18 would have reached the model provider unchanged.

Once a request leaves, users can see almost nothing of who it passes through. In November 2026, HD Moore of Dragos published an experiment. Over five months, the team sent about two million prompts carrying decoy credentials to widely used AI services, and found attackers actively stealing data from three hosting providers. Some of the decoy AWS keys were tried within hours of the request going out. The write-up puts it bluntly: “every hop can see the entire prompt and response.”

How the model works with a reference

The simplest approach is masking: replace the token with asterisks before it goes out. But the agent's next step is to build a curl command with it, and a model that only has the asterisks writes a command that won't run. So the replacement has to be reversible, and the reversal has to wait until the moment a tool actually runs.

That is what Seal secrets does. Before a request goes to the model, the gateway hands its text to OpenViking Server (the Server from here on), which replaces the secrets with references:

{{ov_privacy:alice:viking://~/privacy/credential/github#/values/token}}

A reference names the owner, the entry the secret is stored in, and the field. It is not the secret itself, and only alice's own OpenViking identity can turn it back into the real value.

The model gets the reference and writes tool calls as usual. Below is one recorded tool call on both sides of the gateway, cut down to the curl part: we removed the directory change before it and the command that printed the response body after it.

What the model wrotemodel → gateway
curl -sS -o /tmp/whoami_body.txt -w "HTTP %{http_code}\n" -H "Authorization: Bearer {{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}" http://127.0.0.1:8787/whoami
OpenViking Gateway · unsealonly tool-call arguments are swapped
What pi runsgateway → client
curl -sS -o /tmp/whoami_body.txt -w "HTTP %{http_code}\n" -H "Authorization: Bearer ghp_JY0g…" http://127.0.0.1:8787/whoami
Only the curl part is shown. The test service accepts only the real token, and it returned HTTP 200.

Before handing the reply to pi, the gateway turned the reference in the tool arguments back into the real value, so pi ran curl with the real token. The test service accepts only the real token, and it answered:

HTTP 200
{"login": "alice", "scopes": ["repo", "read:org"]}

References are turned back into real values only in the arguments of client tool calls. The real value never appears in the text the model writes for you, and the gateway's own records keep only the reference.

It works in the other direction too. Later we had the agent write the token into .env, get the deploy script working, and then read the file back.

The .env on disktool result → gateway
GITHUB_TOKEN=ghp_JY0g…
OpenViking Gateway · sealregistered values in tool output are replaced too
What the model readsgateway → model
GITHUB_TOKEN={{ov_privacy:alice:viking://~/privacy/credential/github#/values/token}}
The deploy script ran with the real value on disk; the model only ever saw the reference.

Its reply, translated from Chinese: “The file on disk really does hold the real token; OpenViking just sealed it into a reference on my side… If you want to see the real value, just run cat .env in your own terminal.”

Now back to the numbers. Over the same 8 requests, the token appeared 18 times on the client side and 0 times in the request bodies the gateway sent to the model. We later recorded the session three more times with other models, and the steps the model took differed a little each time. Across the four recordings, the client-side count ranged from 18 to 28. The model side was 0 every time.

Sent by the clientclient → gatewayeach block = oneghp_JY0g…in a request body
18times
1
1
2
2
2
3
3
4
OpenViking Gateway · sealevery token becomes a reference
Received by the modelgateway → model
0times
0
0
0
0
0
0
0
0
Model requests
12345678
Turn 1 · requests 1–4User pastes the token and asks the agent to test it against the API
Turn 2 · requests 5–6Write it to .env, run the deploy script
Turn 3 · requests 7–8Ask the agent to read .env back
  • Turn 1 · requests 1–4User pastes the token and asks the agent to test it against the API
  • Turn 2 · requests 5–6Write it to .env, run the deploy script
  • Turn 3 · requests 7–8Ask the agent to read .env back
Same three turns · re-recorded with other models · client side / model side
Re-recording 110 model requests28/0
Re-recording 212 model requests27/0
Re-recording 312 model requests23/0
Counts are occurrences of the full token string in request bodies. Every request carries the whole conversation history, so the counts add up turn by turn.

Here is the whole trip a token makes, from being pasted in to being used:

Toward the modelBack to youReal value in transitReference in transit
You and your tools
The client, where the real value is used
OpenViking Gateway and Server
The sealing layer
Model provider
Sees only references
You and your tools1You paste a token into the chat ghp_JY0g…
OpenViking Gateway and Server2The gateway sends the request text to the Server to seal: the new token is stored as auto/github-6t8f24 and replaced with a reference
With sealing on, only references cross this line
Model provider3The model receives the reference and a note {{ov_privacy:…}}
Model provider4The model writes the reference into a tool call: curl … Bearer {{ov_privacy:…}}
OpenViking Gateway and Server5The gateway gets the real value back from the Server, in tool-call arguments only, and hands the call to the client
You and your tools6Your tool runs with the real value ghp_JY0g… HTTP 200
OpenViking Gateway and Server7The tool output comes back through the gateway and is sealed again
Model providerThe model still reads only the reference
Full reference{{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}
One new token through one turn. The real value only ever travels between your machine and OpenViking.

Chinese writing on privacy-preserving computation has a phrase for this, 可用不可见, roughly “usable but not visible”: the agent can use the secret, and the model can't see it. The idea isn't new. 1Password's op:// references and op run have long done this on the command line: the config holds a reference, which is resolved to the real value only when the command runs. Seal secrets brings the same idea to the gateway. It applies to every message and every tool call that passes through, and the client needs no changes.

The model named a secret it never saw

In the comparison at the top, the reference pointed to auto/github-6t8f24. The token hadn't been stored before. OpenViking's detector recognized it as a GitHub token, stored it in the auto category under a generated name, and appended a note to the message asking the model to save it under a proper name.

How does a model save a value it can't see? It passes the reference itself as the value. Here are the recorded call arguments:

{
  "category": "credential",
  "target_key": "github",
  "values": {
    "token": "{{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}"
  },
  "description": "GitHub PAT used by acme-site deploy.sh (scopes: repo, read:org)"
}

The Server sees that the value is a reference to the caller's own entry, so it moves the real value to credential/github on the server side and deletes the temporary entry in auto. From that point on, the conversation uses the credential/github reference. It's the one the model saw when it read .env earlier.

Step
The model's sidereferences only
Inside the Serverthe real value lives here
AStored automatically
The model's sideSees only a referenceThe token in the message is already a reference:
{{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}A note follows it: save this token under a proper name.
Inside the ServerStored under a temporary name
auto/github-6t8f24
token = ghp_JY0g…
BCalls privacy_upsert
The model's sideCalls privacy_upsert with the reference as the value
{"category": "credential", "target_key": "github", "values": {"token": "{{ov_privacy:alice:viking://~/privacy/auto/github-6t8f24#/values/token}}"}, "description": "GitHub PAT used by acme-site deploy.sh (scopes: repo, read:org)"}
GatewayAn OpenViking tool, so the reference passes through unchanged
Inside the ServerRecognizes a reference to its own entry
auto/github-6t8f24
token = ghp_JY0g…
CMoved to the proper name
The model's sideGets a new reference back and uses it from then on{{ov_privacy:alice:viking://~/privacy/credential/github#/values/token}}
Inside the ServerReal value moved under the proper name
credential/github
token = ghp_JY0g…
auto/github-6t8f24temporary entry deleted
The model wrote the description itself after reading the project's deploy script. Throughout, only references ever appeared on the model's side.

Rotating the token takes no extra work either. If you switch to a new token later, the old value left in earlier messages is still replaced with this field's reference.

By this point the model had used the token in a working API call, given it a name, and written a description of it from the project's deploy script, without seeing it once.

Automatic detection works for credentials with a fixed format, such as GitHub, OpenAI, Anthropic and Slack tokens, and AWS and Volcengine access key IDs. There are 207 built-in rules, 191 of them from the open-source project Betterleaks (MIT licensed). The detector can't recognize values with no fixed format, such as database passwords or AWS secret access keys. Store one by hand once, and it is sealed from then on:

ov privacy upsert credential prod-db --field password='<your database password>'

Turning it on

You need OpenViking Server 0.5.7 or later. If you haven't used the gateway yet, follow the gateway quickstart to enable it, issue a gateway key, and point your agent's model endpoint at the gateway. With Claude Code, for example:

export ANTHROPIC_BASE_URL=https://ov.example.com/gateway
export ANTHROPIC_AUTH_TOKEN='<gateway key>'
export CLAUDE_CODE_GATEWAY_HINT_HEADERS=1

Then, in Studio (OpenViking's web console), go to OpenViking Gateway and open the Profiles tab. Every gateway key is bound to a context profile, which tells the gateway how to handle that key's requests. Pick the profile your key uses and turn on Seal secrets.

Two switches on a context profile page in Studio: “Seal secrets” is on, and “Also store secrets found in tool output” is off
The two switches in Studio. The second one is off by default.
Studio labelAPI nameDefaultWhat it does
Seal secretsseal_secretsOffReplaces registered secrets, and new tokens the user types, with references; client tools get the real value
Also store secrets found in tool outputenroll_tool_secretsOffAlso stores new tokens found in tool results and attached content. Only works while Seal secrets is on

A change takes effect right away, including in conversations already under way. Clients cannot change either switch with a request header.

To check that it's working, look at the gateway's request log. For each request it records how many texts were sealed, how many values were newly stored, how many references were turned back into real values, and how long sealing took. Studio's Requests page doesn't show these fields yet; read them through the management API at GET /gateway/admin/logs. Here is the entry for the first request above, trimmed to the sealing fields:

{"secrets_sealed": 1, "secrets_enrolled": 1, "secrets_unsealed": 0, "seal_calls": 2, "seal_cache_hits": 22, "seal_ms": 25.59}

The log records only counts, never a value or a reference. In this recording, sealing took between 3.7 and 25.6 ms per request across the 8 requests. The gateway and the Server ran on the same laptop, so treat these numbers as a rough reference only.

What it does not cover

Sealing guards against secrets being sent out by accident during normal use. These things are outside its scope:

  • A malicious model, or an untrusted local machine. In the end the real value is handed to the tools on your machine. If that machine can't be trusted, sealing can't help.
  • The client's own transcript. The text you pasted and the tool arguments with real values swapped back in both stay in the client's local history. The command that wrote .env, for example, shows the real token in pi's interface.
  • Values it doesn't recognize. These include values shorter than 6 characters, values with no fixed format that were never stored, and values you have added to never_mask.
  • Non-JSON request bodies. File uploads, for example, are forwarded unchanged.
  • OpenViking tools without openviking in their name. The gateway recognizes OpenViking's own tools by name. If you registered the MCP server under a different name (ov, say), calls such as privacy_upsert and write are treated as ordinary tool calls. The references in their arguments are turned back into real values like any others, instead of reaching the Server unchanged as they did earlier.

The full list is in the documentation.

Try it

Upgrade the Server to 0.5.7, turn on the switch in Studio, paste in a test token, then call GET /gateway/admin/logs and look for secrets_sealed in the request log it returns.

You can also do without the gateway. The Claude Code memory plugin and the pi extension got the same feature in this release, as a sealSecrets setting that is off by default. Sealing and unsealing happen in local hooks, which call the same Server endpoints. Their coverage is narrower than the gateway's: the Claude Code plugin, for example, doesn't handle the system prompt, slash-command arguments, or messages from before the setting was turned on. See each one's README for details.

A stored secret isn't limited to this one agent, either. Any other agent or script using the same OpenViking identity can use it with just the reference, through ov privacy run. The command contains the reference, the real value is injected only into the child process, and if the real value turns up in output printed to the terminal, it is replaced with the reference again.

ov privacy run --env GITHUB_TOKEN='{{ov_privacy:alice:viking://~/privacy/credential/github#/values/token}}' -- gh api user