guardry/

guardry/Guides/Replace .env files

How to replace .env files for AI coding agents

Import the .env file into a vault, give the agent a scoped credential, and start your program with guardry secrets run, then delete the file.

To replace a .env file, import it into a Guardry vault, create an agent credential scoped to that environment, and start your program with guardry secrets run. The values go into the program's environment and nothing is written to disk. Once the program runs that way, delete the file.

Why a .env file is a problem with an agent

A .env file is a plain-text file. An agent that can read your workspace can read all of it, so it holds every key in the file at once, whether the task needs one of them or none. Nothing records which keys it looked at.

In a vault, each agent has its own credential with a scope, permissions and a lifetime, and every value released to it is written to the audit log.

Before you start

You need a Guardry account (Request an invite) and the guardry CLI on the machine where the agent works.

# Install the CLI and the agent skill (macOS, Linux)
curl -fsSL https://app.guardry.ai/install.sh | sh

1. Import the file

In the dashboard, choose the environment the program runs in, for example main / development, and import the .env file or paste its text. One import takes up to 100 entries and 512 KiB, with 16 KiB per value. Nothing in the file is executed, and names that already exist are skipped.

Each entry is a secret (value hidden) or a variable (value visible). Keep anything sensitive as a secret, because a variable is visible to every agent credential that covers its environment.

2. Create a credential for the agent

Under Agent access, create an agent credential. Set its scope to this one environment, give it the permission to read secret values, and pick a lifetime: 1 hour, 4 hours, 7 days or 30 days. Add a name prefix such as STRIPE_ if the agent needs only one group of keys. The credential is shown once.

3. Sign the CLI in

# Paste the credential at the hidden prompt, not into a chat
guardry login --profile coding-agent
guardry --profile coding-agent whoami

4. Run the program without the file

# The named secrets go into the program's environment; nothing is written to disk
guardry --profile coding-agent secrets run --secret API_KEY --secret DATABASE_URL -- python agent.py

The CLI does not cache secret values, and it removes GUARDRY_* variables from the environment of the program it runs.

5. Verify, then remove the file

Move the file out of the workspace and check that the program still works. Guardry does not delete the source file, so delete it yourself once you are sure.

What this does not do

  • An agent that can read a secret can copy it. Guardry controls who gets a value and records every release; it cannot control what a program does with a value afterwards.
  • Importing does not change your keys. A key that an agent already read from the old file is the same key until you replace it at its provider. Guardry does not rotate keys at the provider.

Questions

Does Guardry delete my .env file after importing it?

No. Guardry does not delete the source file. Check that your program runs with guardry secrets run, then delete the file yourself.

Can I replace a .env file in CI as well?

Yes. Give the runner its own agent credential, set GUARDRY_URL=https://app.guardry.ai and a protected GUARDRY_TOKEN (or GUARDRY_TOKEN_FILE), and start the job with the same guardry secrets run command.

Can the agent still read every key at once?

It can read what its credential covers and no more. Narrow the credential to one environment and a name prefix, or choose the permission that needs a person's approval for each request. Every value it reads is written to the audit log before it leaves the vault.