How to manage environment variables with 1Password

By

Updated

Tagged: Security

Learn how 1Password Developer Environments store, share, mount, and inject project secrets, including their security model and practical limits.

Most apps need secrets like database URLs, API tokens, signing keys, and third-party passwords. During local development, we almost always drop them into a .env file because it’s quick and nearly every framework reads it out of the box.

The catch is that a .env file is still just plaintext sitting on your disk. It’s easy to commit by accident, sweep into a backup, let another app index it, or forget it on an old laptop. Putting .env in .gitignore stops git add from picking it up, while the file itself remains completely unprotected on your machine.

1Password Developer Environments let you keep that same environment-variable workflow without leaving plaintext files around. You store the variables in 1Password, and from there you can mount them as a local .env path, inject them into a command, read them from code with an SDK, share them with teammates, or sync them to AWS Secrets Manager.

What a 1Password Environment is

A 1Password Environment is a set of key-value pairs for a single project or deployment stage. A web app, for instance, might have three separate Environments:

  • shop-development
  • shop-staging
  • shop-production

Inside each one, you store standard key-value pairs like these:

DATABASE_URL
RESEND_API_KEY
STRIPE_SECRET_KEY
SESSION_SECRET

They look like regular environment variables because that’s what your app receives at runtime. What changes is where those values sit before you start the program.

Instead of living in plaintext on disk, they live inside 1Password as a dedicated object built for app configuration, separate from your regular vaults and Login items. That structure makes it straightforward to keep a project’s full config together, switch between stages, and grant a teammate or service account access to just one Environment rather than the rest of your 1Password data.

Environment variables are not a vault

Before we set anything up, keep in mind that environment variables are just a way to pass values into a process. The moment a secret lands in a process’s environment, that app can read it, child processes can inherit it, and debuggers, crash reports, logs, or third-party dependencies might leak it.

1Password helps with everything that happens before the process starts:

  • your values don’t sit around in plaintext project files
  • you can scope access down to a single Environment
  • your team shares one managed copy
  • you can inject values only for the lifetime of a single command
  • the 1Password CLI can mask secret values if they get printed to output

Your running code still receives the real value so it can connect to your database or API. What 1Password Environments fix is how those secrets are stored, shared, and handed over to the process.

If you’re new to environment variables in general, start with my guide to setting environment variables in Bash and zsh.

Create your first Environment

You create and manage Environments in the 1Password desktop app on Mac, Windows, or Linux. Before you begin, an Owner or Administrator needs to enable the Environments policy for your account.

Open 1Password, click Developer in the sidebar, and choose View Environments:

The 1Password Developer screen with arrows pointing to Developer and View Environments

Click New environment:

The 1Password Environments screen with the New environment button highlighted

Give it a clear name like example-development, pick the 1Password account it belongs to, and hit Save:

The 1Password New environment dialog naming the environment example-development

Next, populate it with variables. You can either add them one by one or import an existing .env file, which parses the key-value pairs for you:

The example-development Environment with options to import a .env file or add a variable

If you add one manually, enter its name and value and click Save:

The 1Password variable editor with fields for a variable name and value

A small setup looks something like this:

API_BASE_URL=https://api.example.test
API_TOKEN=replace-me
LOG_LEVEL=debug

By default, 1Password conceals every value in the UI, though you can mark non-sensitive config to display in plain view. That’s handy because an Environment holds both kinds of data: LOG_LEVEL=debug is just normal configuration, while API_TOKEN is a real secret. Keeping everything in one place is convenient as long as you keep track of which fields are sensitive.

If you’ve got lots of projects scattered across your machine, 1Password Developer Watchtower can scan for plaintext .env files and help you import them. Once you import a file, double-check that every variable came through cleanly, then delete the old plaintext copy so it doesn’t sit around next to the new setup.

Four ways to use an Environment

Once your variables are in 1Password, you need to get them into your app. You’ve got four main ways to do that, depending on where your code runs:

  1. Mount the Environment as a local .env file.
  2. Inject the variables into a command with the 1Password CLI.
  3. Read the variables directly from your code with a 1Password SDK.
  4. Sync the Environment to AWS Secrets Manager.

Mount an Environment as a local .env file

If your project already loads a .env file, mounting the Environment locally is the fastest way to switch over.

Open the Environment in 1Password, look under Connect to, click Connect next to Local .env file, and pick the path inside your project directory.

You’ll now see a .env entry in your folder, except 1Password never writes your secrets to disk there. Instead, that path is a Unix named pipe (also called a FIFO). When your app reads the pipe, the flow looks like this:

application opens .env
        ↓
1Password asks you to authorize the read
        ↓
1Password sends the values through the pipe
        ↓
the application receives normal KEY=VALUE lines

When a process opens .env, the plaintext values stream straight through the pipe to that process without ever being saved inside the file. Your framework keeps reading .env as usual and doesn’t need to know 1Password is behind it.

You can test the mount right from your terminal:

cat .env

1Password prompts you to authorize the read, and once you approve it, the variables print out in your terminal.

To confirm the path is a named pipe rather than a regular file, run this check:

test -p .env && echo "1Password mount is active"

Stick to that check instead of test -f, since test -f returns false for a named pipe.

This setup plays nicely with standard dotenv tooling like Node.js dotenv, Python python-dotenv, Docker Compose, Go godotenv, and PHP phpdotenv.

One platform caveat before you roll it out to everyone: you can create and manage Environments on Mac, Windows, and Linux, while local .env mounts only work on Mac and Linux right now. On Windows, you’ll want one of the other 1Password developer workflows instead.

Migrate an existing Git project carefully

If Git never tracked your .env file, switching over takes five quick steps:

  1. Import the file into a 1Password Environment.
  2. Verify that every variable came across properly.
  3. Delete the plaintext .env file.
  4. Mount the Environment at the same path.
  5. Keep .env in .gitignore so nobody reintroduces a plaintext copy later.

If Git already tracks .env, untrack and remove it from the repo and commit that change before you create the mount. If you mount first, Git can keep flagging the path as a tracked change even though it’s now a named pipe whose contents can’t be staged normally.

Remember that deleting .env from the current branch still leaves old values in your Git history. If a real secret ever made it into a commit, treat it as compromised. Rotate it first, then decide if you also need to scrub the repo history. The same rule holds when a hosted AI tool stored the key. Rotating the credential is what closes the exposure, while rewriting history just clears old copies out of normal access paths.

Inject variables with 1Password CLI

A local mount is great for day-to-day development, while for scripts, task runners, CI jobs, or one-off commands, I prefer injecting variables explicitly.

With the 1Password CLI, you can launch a child process loaded with an Environment’s variables:

op run --environment <environment-id> -- node app.js

Those variables live only inside that child process for as long as the command runs. Inside your app, you read them the same way you always do:

const apiBaseUrl = process.env.API_BASE_URL
const apiToken = process.env.API_TOKEN

To grab an Environment’s ID, open Manage environment in the 1Password desktop app and copy it from there.

If you need to inspect an Environment straight from the terminal, you can read it with:

op environment read <environment-id>

Be careful with that one, since it outputs plain KEY=VALUE lines. Don’t pipe it into logs or dump it into a temporary file.

When op run encounters a variable marked as hidden, it masks that value in stdout and stderr by default. That keeps accidental logging from leaking secrets, while the program itself still gets the real value it needs to run.

Version-wise, op run --environment has been in the stable CLI since 1Password CLI 2.41. op environment read is still in beta and requires beta CLI build 2.33.0-beta.02 or later. Check the current CLI instructions before wiring either command into a critical pipeline.

For CI and other automation, authenticate with a service account that only has read access to the specific Environments that job needs, rather than your personal 1Password account or every production secret. That service account token becomes your bootstrap secret, so keep it in your CI platform’s protected secret store, restrict who can edit it, and rotate it whenever needed.

Read variables with a 1Password SDK

1Password also ships SDKs for Go, JavaScript, and Python. Your app can authenticate through the local desktop app or a service account, then pull all the variables from an Environment using its ID.

That’s handy when you’re building a deeper integration and don’t want to wrap every command with op run. It does change how your app is wired, though: your code now depends on the 1Password SDK and its auth flow, and fetching secrets becomes part of startup. You’ll also need to handle what happens if 1Password is unreachable, access gets revoked, or a variable has a bad value.

My advice is to use the SDK when 1Password is a real part of your app’s architecture, not for a small project just to avoid typing one wrapper command at startup.

You can find up-to-date examples for all three languages in the programmatic access guide.

Sync an Environment to AWS Secrets Manager

If your app runs on AWS, 1Password can sync an Environment straight to AWS Secrets Manager. Your team keeps managing the variables in 1Password, and your app keeps reading them through standard AWS runtime integrations.

The sync only goes in one direction:

1Password Environment → AWS Secrets Manager → AWS application

Anything you change on the AWS side stays in AWS and never flows back to 1Password.

Keep in mind that this integration is still in beta. A synced Environment has to fit within the size limit of an AWS Secrets Manager secret, and if AWS already handles automatic rotation for a secret, leave AWS in charge of it so the two systems don’t end up overwriting each other.

The AWS Secrets Manager integration guide walks through setting up the SAML provider, IAM role, permissions, and sync configuration.

Share Environments with a team

Sharing an Environment cuts out a lot of onboarding friction. Instead of sending .env files through chat every time a key changes, you grant access in 1Password and everyone pulls from the same place.

Permissions work per Environment, so you can give a person or a group view, edit, or manage access. That makes it easy to keep stages separated. A developer working locally can get shop-development without ever touching shop-production, and a deployment service account can get read-only access to production so it can deploy without changing any values.

Avoid dumping every project and stage into one giant Environment. Smaller, focused Environments are much easier to audit, rotate, and lock down as your team changes.

One thing to watch out for is that 1Password returns whatever values someone saved in there, verbatim. If you’re using a shared Environment in a sensitive workflow, review edits to URLs, shell fragments, and config values before you use them.

What happens when the local mount is unlocked

There’s an important security boundary to understand with local .env mounts.

The first time a process reads the mounted file, 1Password asks you to authorize it. Once you approve, that mount stays unlocked until 1Password locks or you disable the mount. While it’s open, 1Password doesn’t check which specific command is asking for the file: any process running under your user account can read it.

That means an untrusted package, script, editor extension, or AI tool running during that window can read the same secrets your dev server can. A few habits help keep the exposure small:

  • mount only the variables that project needs
  • keep development and production secrets separate
  • lock 1Password as soon as you’re done with sensitive work
  • avoid running untrusted code while an important Environment is mounted
  • rotate a secret right away if you think something unexpected may have read it

If you use AI coding tools, 1Password also provides an agent validation hook for Cursor, Claude Code, GitHub Copilot, and Windsurf. Before an agent runs shell commands, the hook checks that the required mount paths exist, are enabled, and are valid named pipes. It only checks that the mounts are wired up properly, so once a mount is unlocked, any authorized process in your session can still read the values.

For the Cursor plugin, skill, and hook setup, see Use 1Password Developer Environments with Cursor.

Developer Environments are meant for project .env secrets rather than website logins. If you want AI agents to log into websites without the model seeing your passwords, check out How AI agents can log in without seeing your passwords.

Local mount limitations

Using a named pipe keeps plaintext secrets off disk, though a FIFO behaves a bit differently from a regular file.

Concurrent reads can fail

A mounted pipe isn’t built for several processes reading it at the same time. If your editor has .env open while your dev server tries to read it, one of them may succeed while the other hangs or fails. Keep the mounted .env file closed in your editor.

File watchers can restart forever

Some tools watch .env and restart whenever it changes. Because opening and closing a FIFO can emit filesystem events even when no value changed, tools like Vite can get stuck in a restart loop.

If your project doesn’t need .env hot reloading, tell Vite to ignore the mounted path:

import { defineConfig } from 'vite'

export default defineConfig({
  server: {
    watch: {
      ignored: ['**/.env'],
    },
  },
})

Hot reloading for your regular source files will keep working as usual.

Offline access uses the latest local state

When you’re offline, you can still access the latest Environment contents synced to your machine along with any local edits you’ve made. Changes from teammates will appear once 1Password can sync again.

A device can have up to ten enabled mounts

Each machine supports up to ten active mounts at a time. That’s plenty for active work, and it pushes you to keep only the projects you’re working on enabled and disable the rest.

How I would use 1Password Environments

My advice is to start with local development. Create one development Environment per active project, mount it at the path the project already expects, and put only the variables that project needs inside it. Skip the temptation to drop production keys into a local Environment for convenience.

When you need to run a command with more sensitive values, reach for op run instead of leaving a mount unlocked in the background. Running through op run makes it clear exactly when secrets enter the command:

op run --environment <environment-id> -- npm run task

On a team project, split development, staging, and production into separate Environments. Give each person the smallest set of access they need, and use narrowly scoped service accounts for automated jobs.

For Cloudflare Pages projects, keep runtime secrets in Cloudflare’s protected secret store. If your team uses 1Password as the source of truth, make copying values into Cloudflare a deliberate deployment step and document which system is authoritative during a rotation. Either way, don’t make every application request call 1Password. Load secrets at startup or let the deployment platform provide them.

On AWS, the native Secrets Manager sync is worth considering since it gives your app an AWS-native runtime path. Leave out any secret that AWS rotates on its own.

Above all, keep the setup boring. Use one Environment per clear boundary, stick to familiar variable names, keep shell code out of values, and don’t throw everything into one giant shared collection.

When I would not use it

You can skip 1Password Environments if any of these match your setup:

  • your team doesn’t already use 1Password
  • local development happens mostly on Windows and requires mounted .env files
  • your toolchain constantly or concurrently reads .env
  • your runtime already has a well-managed native secret store and adding another source would create confusion
  • your application needs a KMS or HSM that runs cryptographic operations without exposing key material
  • you’re working on a tiny project with only public config values and no secrets

It makes the most sense when your project already reads .env files for sensitive values and you want one controlled place to manage them.

The main idea

You don’t have to change how your apps read configuration to stop leaving plaintext .env files on disk or trading them in chat. Your code keeps reading the same variable names through local mounts, the CLI, the SDK, or AWS Secrets Manager sync, while your team gets clearer per-Environment permissions behind the scenes.

Remember that once a secret reaches a running process, that process can use it. 1Password handles storage, access control, and delivery, so your job is to keep each Environment scoped tight and keep the runtime boundary as small as you can.

Want me to talk about your product? You can sponsor this site.

Related posts about security: