· homelab · security · agents · go
Letting agents use secrets they never see
How I give coding agents API tokens in my homelab without the values landing in their context: snake run, --redact, and Bitwarden as the sync layer.
More and more of my homelab work happens through coding agents. I ask one to run
a terraform plan, poke an API, or fix a deploy script, and it does the typing. That
works well right up until the command needs a token.
The obvious options are all bad:
- Paste the token into the chat. Now it lives in a transcript, maybe in a provider’s logs, and in every summary the agent writes of the session.
- Export it in the shell the agent uses. Then
env,set -x, a verbose flag or a stack trace prints it, and the output goes straight into the model’s context. - Put it in a
.envfile. The agent cancatit, and sooner or later someone commits it.
What I wanted was narrower: the agent can cause a command to run with a secret, but the value never shows up in anything the agent reads. This post is how I solved that for my own homelab with a small Go tool called snake. It is a personal tool sized for one person and a handful of machines, not a recommendation for how a team or a production system should handle secrets. If you need that, use a real secrets manager with audit logs and short-lived credentials.
Where it started: Skate
Snake owes its shape to Skate, a small tool from Charm, the people behind Bubble Tea and a lot of the nicer terminal tools I use. Skate calls itself “a personal key-value store”, and that’s exactly what it is:
skate set kitty meow
skate get kitty
skate list @work-stuff
You set a value, get it back, list what’s there, and split things into
separate databases with key@db. Binary data goes in on stdin, Unicode just
works, and skate list pipes cleanly into other tools.
Skate used to be more than that. Up to v0.2.2 it ran on Charm Cloud: values
were encrypted on the client, synced through Charm’s servers (or your own, if
you self-hosted), and skate link joined machines together, with SSH keys as
your identity. Skate v1.0.0 went local-only, and Charm sunset Charm Cloud on
29 November 2024, with a migration script in the release notes for getting
your data out of the old version.
Today Skate is a local store on BadgerDB, and it’s still maintained. v1.1.0
came out in September 2026 with a --copy flag for the clipboard, command
aliases, and a --store flag (or SKATE_STORE) to choose where the data
lives. Its README suggests keeping passwords in their own database, but as
far as I can tell from the source, the local store isn’t encrypted at rest.
What snake borrowed
Pretty much the whole command line. set, get, list, list-dbs and
delete, the key@db addressing, the list flags (-k, -v, -r, -d,
-b), binary values on stdin, and even the examples: snake’s README still
has kitty, meow and penelope’s marmalade, because they were good examples. If
you know Skate, you already know half of snake. None of Skate’s code is in
snake, though. It’s the same interface, written again from scratch.
The other thing I took is an idea from Skate’s own README, a section called “Keep secrets out of your scripts”. Snake is that idea pushed one step further: keep secrets out of the agent’s context too.
Where snake went its own way
Skate’s interface hands the value back to you, as in $(skate get gh_token)
in a script. That’s the right shape for a person at a keyboard and the wrong
one for an agent, and closing that gap is what the rest of this post is
about. The differences:
- Encrypted at rest. Snake encrypts every value locally, with a key tied to an identity key on each machine.
- Sync. Skate syncs nothing now, and I needed my secrets on several machines. Snake syncs through Bitwarden (more on that below).
- Running commands instead of printing values.
snake runand--redacthave no equivalent in Skate. - Safety nets for secrets. Tombstones so deletes propagate, a history of
old values with
snake restore, backups, andsnake doctorto check a machine’s setup. - Storage. SQLite instead of BadgerDB.
What snake is
The everyday commands are still Skate’s:
snake set kitty meow
snake get kitty
snake list @work
Values live in a local SQLite file, encrypted with AES-256-GCM. The data key
is random, and it is wrapped with a key derived (HKDF-SHA256) from an Ed25519
key at ~/.ssh/id_snake. Each machine has its own identity key. Key names
are stored unencrypted, which is what lets shell completion work without
unlocking anything.
Two features turn it from a key/value store into something an agent can use
safely: snake run and --redact.
snake run: inject, don’t reveal
snake run decrypts the secrets you name and puts them in one child
process’s environment, then runs your command:
snake run -e TF_VAR_api_token=my-api-token -- terraform plan
Nothing is exported in the parent shell, nothing lands in shell history (the command line names a key, not a value), and nothing is written to disk.
Because the mapping only contains key names, it can live next to the project and be committed:
# .snake.env
TF_VAR_api_token=my-api-token
export DNS_API_TOKEN=dns-api-token
snake run -f .snake.env -- terraform apply
There is also --from @db, which exports every key in a database, turning
my-api-token into MY_API_TOKEN. Later sources win: --from, then -f,
then -e.
A few details that mattered more than I expected:
- All or nothing. Every mapping is resolved before anything runs. If three
keys are missing, you get one error listing all three, and the command never
starts. A half-configured
terraform applyis worse than none. - Trailing newlines.
echo token | snake set kstorestoken\n. One trailing newline is trimmed on injection unless you pass--no-trim, which saved me from a whole class of “401 but the token is right” bugs. - Exit codes pass through, and SIGTERM is forwarded, so
snake runis transparent to scripts and to the agent. - No NUL bytes. A value with a NUL can’t be an environment variable, and snake says so instead of silently truncating.
For an agent, this is the whole interface. It never needs snake get. It
writes snake run -f .snake.env -- <command> and the token goes from my vault
into the process without passing through the conversation.
--redact: the output problem
Injection solves half the problem. The other half is that programs print
their environment. env, set -x, TF_LOG=debug, a curl with -v, a
Python traceback that dumps os.environ: any of these puts the secret
straight into the agent’s context, and from there into whatever it writes
next.
So snake run --redact wraps the child’s stdout and stderr and replaces every
injected value with a label:
$ snake run --redact -e TOKEN=my-api-token -- sh -c 'echo "using $TOKEN"'
using [REDACTED:TOKEN]
The implementation is a small streaming writer, and most of the interesting work is in the edge cases:
- Values split across writes. A program might write
tok=s3cr3in onewrite()andt-tokenin the next. The writer holds back output only while it could still be the start of a secret, and only up to the length of the longest value minus one byte. Ordinary output passes through immediately. Whatever is still held when the command exits gets flushed. - Overlapping values. If one secret is a prefix of another (
hunter22andhunter22-extended), the longest match wins, and the writer waits for more bytes rather than committing to the short match too early. - Short values are skipped. Anything under 4 bytes is not redacted.
Replacing every
devor1in the output would wreck it and hide nothing. - It redacts exactly what was injected. With
--no-trim, the trailing newline is part of the match. - Grandchildren can’t hang it. If the command leaves a background process holding the pipes open, snake waits two seconds after the command exits and then cuts them off, instead of hanging forever.
The cost: the command now writes to pipes instead of a terminal. Some tools turn off colour, buffer differently, or refuse to run interactively. For agent use that’s fine, since agents don’t have a terminal anyway.
Syncing through Bitwarden notes
I have secrets on several machines, so snake needs sync. My first version had its own relay server: a public endpoint, invite-based registration, per-peer encryption. It worked, and I deleted it. It was another internet-facing service to patch and monitor, guarding the most sensitive data I have.
In hindsight, that relay was a small homemade Charm Cloud: Ed25519 keys for identity, encryption on the client, a server in the middle. Charm shut theirs down in 2024 to keep their team focused on bigger projects. If a company that builds this stuff for a living doesn’t want to run that service, I probably shouldn’t either.
Bitwarden already syncs encrypted data between my devices, so now snake
syncs through it using the official bw CLI:
- Each record becomes one secure note in a
snakefolder, namedsnake/<db>/<key>. - The value is the note body: printable text as-is, anything else (binary, carriage returns) as base64.
- Hidden custom fields carry the metadata:
snake_db,snake_key,snake_content_type,snake_encoding,snake_updated_at,snake_deleted_at. Snake finds its items by folder and fields, so it ignores anything else I keep in that folder.
The merge rules are deliberately simple:
- Last write wins, comparing the later of the updated and deleted times. On a tie with different content, Bitwarden’s copy wins.
- Deletes are tombstones. The note stays, emptied, with
snake_deleted_atset. I don’t rely on Bitwarden’s trash, because it is purged after 30 days and a machine that was off for a month would resurrect the secret. - Editing in the Bitwarden app works. Snake notices the item’s revision
date moved without
snake_updated_atchanging, treats that as a new write, and restamps the note. - Trashing a note in Bitwarden deletes the secret. Snake then restores the item as a tombstone so other machines see the delete too.
- Duplicates resolve to the newest, and the rest go to the trash.
The sync engine is a pure Plan() function (local rows plus vault items in,
a list of actions out) with a separate executor. That split made it easy to
test against an in-memory fake vault, and it gives snake sync --dry-run for
free.
Credential handling follows one rule: secrets never go on a command line.
Item JSON goes to bw over stdin. The master password, API key and session
key go only into the bw child’s environment. The session lives in memory
for one run, or in the background sync process (snake sync start), and is
never written to disk. That process dies on reboot or when the vault locks,
and every snake command then prints a warning until I restart it.
Since values are synced as plaintext notes, the trust model changes: in the vault they are protected by Bitwarden’s end-to-end encryption and my master password, not by snake’s key. Anyone who can unlock my Bitwarden can read my snake secrets. For me that’s an acceptable trade, because that person already has everything else.
There are limits. Notes hold at most 10,000 encrypted characters, which works
out to 7,439 bytes of plaintext. Larger values are reported and skipped, and
attachments aren’t supported. Last-write-wins also depends on clocks, so
snake doctor checks clock skew against the Bitwarden server.
How an agent actually uses it
The agent side is a Claude skill called snake-secrets. It tells the agent
that when a task needs one of my secrets, it uses snake run --redact with a
key name, and nothing else: no snake get, list, history or clip, and
no attempts to print a value.
That’s the whole mechanism. There is no hard block behind it: no permission rule denies those subcommands, and nothing stops an agent that ignores the skill. It works because the agent follows its instructions, which is a convention, not a control.
A typical session looks like this:
snake run --redact -f .snake.env -- terraform plan
The agent sees the plan. If something dumps the environment, it sees
[REDACTED:TF_VAR_api_token]. It never sees the token.
What this does not protect against
This part is important, so I’ll be blunt. The agent runs as my user, in my shell. Snake keeps secrets out of the agent’s context by convention and by accident-prevention, not by enforcement. A model that set out to get a value could:
- run
snake get(only the skill’s instructions stop it); - run
snake run -e X=key -- sh -c 'echo "$X" | base64', because--redactonly catches the literal value, not encoded forms; - read
/proc/<pid>/environof a process it started, or of the background sync process, which holds the Bitwarden session in its environment; - read
~/.ssh/id_snake, which has to be unencrypted, and decrypt the database itself.
What snake does well is stop the common failure: a well-meaning agent, or me, leaking a token through a debug flag, a pasted log, or a transcript. In my experience that’s how secrets actually leak, and it’s the problem I set out to solve.
What I’d do differently
Run the agent as a different user. Most of the list above disappears if
the agent can’t read my home directory or my processes. A small broker
running as me, which accepts “run this command with this mapping” over a
socket and enforces a per-project allowlist of keys, would turn the
convention into an actual boundary. snake run already has the right shape
for that, but it runs in-process.
Scope keys per project. Today snake run can resolve any key, and
--from exports a whole database. A .snake.env should be an allowlist the
agent can’t widen, ideally approved once by me and pinned by hash.
Protect the identity key. id_snake can’t have a passphrase, because the
code parses it raw. I’d use ssh-agent, the OS keyring, or a hardware key, so
“can read my files” no longer means “can read my secrets”.
Redact more than the literal value. Base64, URL-encoding and JSON escaping of each value are cheap to precompute, and they would catch the most likely accidental transformations. It’s still not a security boundary, but it would close the easy gaps.
Rethink snake sync unlock. It refuses to print the Bitwarden session to a
terminal, which is right for shoulder-surfing and exactly backwards for
agents: an agent’s stdout is never a terminal. And if I eval it in a shell,
every agent started from that shell inherits BW_SESSION. I’d rather the
session stayed inside the background process only.
Encrypt key names, or at least accept the leak consciously. Plaintext key names make completion nice, but they tell anyone who reads the database what I have credentials for.
Skip the relay. I don’t regret building it, since I learned a lot, but “use the encrypted sync you already trust” should have been the first idea, not the third.
Wrapping up
The pattern is more important than the tool: agents should reference secrets by name and run commands through a wrapper that injects and redacts, so the value never passes through their context. Snake is my small, homelab sized version of that. If you build your own, start with the threat model section above and decide which of those holes you need to close for real.
The code is on GitHub at github.com/moquito64/snake.