
How to let an AI coding agent run Solana commands without exposing your keypair
Short answer
Assume anything the agent can run can read your files. Keep mainnet keys off the machine, use a throwaway keypair per project, run the agent in a sandbox or container, approve shell commands when there is no sandbox, and test on a local chain. Oh My Sol adds file guards for ~/.config/solana and ~/.ssh, and on macOS runs every command in a Seatbelt sandbox that blocks keypair files. Mainnet work comes back to you as a transaction to sign yourself.
- Who it’s for
- Solana developers who want an AI agent to run builds, tests and CLI commands on their machine, and who keep a wallet or keypair on that same machine.
- Last checked
- , against Oh My Sol 0.1.0
How can an AI agent expose my Solana keypair?
solana-keygen new writes your keypair to ~/.config/solana/id.json by default, and a new Anchor project’s Anchor.toml points its wallet there:
[provider]
cluster = "Localnet"
wallet = "~/.config/solana/id.json"(from the Anchor local quickstart). A coding agent with shell access runs as you, so it can read that file. It does not have to mean to: a command can print it while debugging, copy it into a test fixture, or follow an instruction hidden in a web page, README or package the agent fetched. Once the key bytes are in the conversation, they are in the model provider’s logs and anywhere the transcript goes.
How do I protect my keypair with any coding agent?
- Keep mainnet keys off the machine. Use a hardware wallet or a separate machine for anything with real funds. An agent cannot leak a key that is not there.
- Give each project a throwaway keypair for local tests, outside your default Solana config, and point
Anchor.tomlat it:solana-keygen new --no-bip39-passphrase -o ~/dev-keys/my-program-local.json # Anchor.toml [provider] wallet = "~/dev-keys/my-program-local.json" - Run the agent in a sandbox or container that cannot read your home folder or reach the network beyond what it needs.
- Turn on command approval when there is no sandbox, and read each command before you approve it. Be wary of anything that touches dot folders, pipes a download into a shell, or reaches outside the project.
- Test on a local chain. Local validators need no real funds, so the agent never needs a funded key.
Instructions such as “never read my keypair” in a prompt file help, but they are guidance to the model, not a control. The control has to sit outside the model.
How does Oh My Sol keep the model away from keys?
Oh My Sol (OMS) stacks several layers. Which ones you get depends on your platform:
| Layer | What it does | Where |
|---|---|---|
| File-read guards | Before every read, edit, write, grep, find, ls or bash call, deny ~/.config/solana, ~/.ssh, ~/.oms and ~/.gnupg, after resolving .., ~ and symlinks. | All platforms |
| Shell guard | Scans each shell command’s text for those paths in their many spellings and blocks a match, before the sandbox sees it. | All platforms |
| Seatbelt sandbox | Denies reads under your home folder except the worktree and toolchains, then always denies -keypair.json and /id.json files and .ssh, .config/solana, .aws and other credential folders. Denies the keychain, writes outside the worktree, and all network except the local chain. | macOS, host mode |
| Command approval | Asks you to approve every model shell command, with warnings for sudo, wallet paths, a download piped into a shell and writes outside the worktree. | Host mode without a sandbox, such as Linux |
| Docker mode | Runs commands in a pinned, read-only, non-root container with an explicit network choice. | --sandbox docker or OMS_SANDBOX=docker |
| Credential isolation | Provider API keys never reach commands or the sandbox; each command starts from an empty environment and a private HOME that is removed afterwards. | All platforms |
The model is also told it may create fresh throwaway keypairs only in the task’s own folders, only for tests and local chain setup, and never for devnet or mainnet. oms doctor reports which confinement is active on your machine.
npx @barestate/oms doctorWhat should I set up on Linux?
On macOS the Seatbelt sandbox is on by default. On Linux, run OMS in Docker mode for the same kind of confinement:
OMS_SANDBOX=docker npx @barestate/omsIn Linux host mode there is no operating system sandbox, so OMS asks you to approve every shell command the model runs, and the file guards still apply. Whatever the platform, OMS never holds your mainnet keys: mainnet work comes back to you as a transaction to review and sign yourself. The security overview covers each protection in detail.
Frequently asked questions
Can an AI coding agent read my Solana keypair?
If it can run shell commands as your user with no sandbox, yes. The default Solana CLI keypair lives at ~/.config/solana/id.json, and Anchor projects point their wallet at it by default. Any command the agent writes, or is tricked into writing by text it fetched, can read that file.
What is the safest way to use an AI agent for Solana development?
Keep mainnet keys off the machine the agent runs on, give each project a throwaway keypair for local tests, run the agent inside an operating system sandbox or a container, require approval for shell commands where there is no sandbox, and do your testing on a local chain. Sign anything that matters yourself.
Does Oh My Sol block access to ~/.config/solana?
Yes, in two layers. A guard before every file and shell tool call denies ~/.config/solana, ~/.ssh, ~/.oms and ~/.gnupg. On macOS, every command also runs in a Seatbelt sandbox that denies reads under your home folder apart from toolchains, and always denies keypair files and folders such as ~/.config/solana and ~/.ssh.
How does Oh My Sol protect keys on Linux?
Use Docker mode (--sandbox docker), which runs commands in a pinned, read-only, non-root container. In host mode on Linux there is no operating system sandbox, so OMS asks you to approve every shell command the model runs, and its file guards still apply.
Does Oh My Sol hold my mainnet keys?
No. OMS never holds mainnet keys. Mainnet work comes back to you as a transaction to review and sign yourself, and the agent works against a local Surfpool chain that needs no real funds.
Try it on your own program
Oh My Sol 0.1.0 runs on macOS and Linux, and on Windows through WSL 2. You need Node 22.19.0 or newer and Git. You bring your own model access: an API key, a ChatGPT subscription or a Claude subscription.
npx @barestate/oms doctor --install
npx @barestate/oms