You can now store environment variables as encrypted secrets that are only decrypted when your server starts.
Joel Smith·Nov 25, 2026
·5 min read
To keep our platform and users safe from future incidents, we're introducing encrypted secrets for all projects to protect your LLM API keys, tokens, and other sensitive environment variables. Plaintext secret values are never stored. With this change, secrets stay stored in our platform's key management service and are never written as plaintext to disk, container images, logs, or deploy artifacts, and, importantly, never left in a hosting provider's variable store.
Stolen inference API keys have become one of the fastest ways for attackers to monetize a breach. In October 2026, Wiz Research tracked a "Black October" stretch of security incidents across at least nine AI developer platforms, with attackers hunting stored environment variables for model access. Our own upstream service provider Railway was one of the targets, with attackers going after router and frontier lab API keys stored on their servers.
One of the key problems is that on many platforms, API keys sit in plaintext across variable stores, container images, deploy artifacts, and logs, giving hackers a host of surface areas to attack and discover keys. Combine that vulnerability with powerful, relentless AI agents, and you end up with a recipe for large scale security incidents.
How encrypted secrets work
- When you save a secret: We encrypt it with a unique encryption key and then encrypt that key using a KMS (key management service) managed public key. We store both together as one msec: value in our database. The private key stays in KMS, so database access alone cannot decrypt it.
- When your server starts: Mastra Platform injects your secret values into your running server's process memory at startup—not at build time—and only after a double-key match succeeds.
- Once a secret is saved: You can't read the value back. This is a change from how secrets have historically been accessible in our platform. Going forward, new environments will set secrets to be strictly write-only in both the Mastra Platform dashboard and API, so saved values are never displayed in the UI or returned to clients. In cases where you want a variable to be readable, you can opt that variable out of encryption.
Why startup injection matters
Baking secrets into a build leaves them in every copy of your container image. If an image, build log, deploy artifact, or hosting provider's variable store is leaked, plaintext keys are sitting right there.
With our new encrypted secrets, environment variables and other secrets stay out of builds by default. There’s a narrow exception for private-registry install tokens as they're available only during the install step and are not baked into the image. Unencrypted config variables still pass through as plaintext at build time, so public and client-side config can consume harmless environment variables.
Delivery at startup
- Split-token Authentication: The authorization token is split into two halves. Neither half is enough on its own to fetch your secrets.
- Separated encrypt and decrypt: The platform's API can encrypt secrets, while only the dedicated secrets service can decrypt them for delivery at boot.
- Audited access: Every time a secret is decrypted for a running server, that access is audited.
Using secrets day to day
Every environment variable is either a secret or config. In the dashboard, use the Secret toggle when you save a variable to mark it as a secret or as readable config.
- Write-only across tools: The dashboard and API never return saved secret values. The CLI follows the same rule:
mastra env vars pulllists secret names without writing their values into the file. - Clean rotation: To update or rotate a secret, save the new value from the dashboard. You can't read the old value back. The next time your server starts, it receives your current stored secrets—nothing is baked into an image per deploy.
Next Steps
Existing environments move to encrypted secrets in two steps: you review how your variables were classified, then their values are encrypted in place.
Review encrypted keys
Before an existing environment is switched, your variables are classified as secret or config based on what they look like. You'll see a review banner before values are encrypted, so you can review those and change any that were misclassified. You may want to keep some environment variables readable, so this is your chance to set those correctly.
Migrating to encrypted secrets
- You won’t need to re-enter existing secret values as they will be encrypted in place when your environment migrates.
- You also don't need to change your application code if it already reads environment variables at runtime.
- Once switched, a new deploy or start makes your running app fetch secrets from the platform's KMS at boot, and plaintext values are no longer left in the hosting provider's variable store.
- From then on, treat secrets as write-only: to change one, save a new value.
For more information, see our updated platform docs on encrypted secrets.
Share on X or LinkedIn
Joel SmithHead of PlatformJoel Smith is the Head of Platform at Mastra, leading product and engineering efforts around the entire Mastra platform. A high school English teacher turned software engineer turned product/engineering manager, he previously led product and engineering teams in early stage startups focused on blockchain data, incident management and developer tools infrastructure.
All articles by Joel Smith →More on Security & Compliance
All postsBlogOct 22, 2026Mastra Platform incident report for October 21, 2026
Mastra Platform's October 21 incident report and timeline.
BlogOct 19, 2026Introducing Mastra Studio-scoped SSO
Sign in to Mastra Studio with WorkOS, Okta, Auth0, Clerk, or Google.
BlogOct 8, 2026Multiplayer agents need fine-grained context
What is fine-grained context, or FCA, and how it applies when building multi-user agents.
AI Trends