Skip to main content
You can programmatically access 1Password Environments using 1Password SDKs or 1Password CLI. Both tools can read the secrets in an Environment and pass them to your applications. With 1Password SDKs or 1Password CLI, you can also create, edit, and delete Environments and their secrets.
DeprecationThe following functionality is deprecated and will be removed on January 20, 2027:
  • The op environment read command in 1Password CLI. To list the secrets in an Environment, use op environment secret list instead, available in version 2.42.0 or later. To pass secrets from an Environment to an application or script, use op run --environment.
  • The get_variables() function in 1Password SDKs, and the GetVariablesResponse and EnvironmentVariable types it returns. Use list_secrets() instead, available in Go SDK 0.5.0, JavaScript SDK 0.6.0, and Python SDK 0.5.0 or later. It takes an Environment ID or name and a reveal option, and returns a list of EnvironmentSecret objects directly, without a response wrapper.

Choose your configuration

Tool options

  • 1Password CLI: Best for quick testing, shell scripts, CI/CD pipelines, Infrastructure as Code, build tools and task runners.
  • 1Password SDKs: Best for native integrations with Go, Python, or JavaScript applications.

Authentication options

  • Local authentication with the 1Password desktop app: Authenticate in the same way you unlock your 1Password desktop app, like with biometrics or your 1Password account password. Requires minimal setup with no token management. Enables human-in-the-loop approval for sensitive workflows.
  • 1Password Service Accounts: Authenticate using a service account token scoped to the Environments you want to access. Best for shared building, automated access, and headless server authentication. Enables you to follow the principle of least privilege in your project.

Decision guide

Use the table below to find the best tool and authentication method for your specific use case.

Get an Environment’s ID

1Password SDKs and 1Password CLI accept an Environment’s unique identifier (ID) or its name. The exception is op run --environment, which requires the ID. Use the ID if two Environments share a name. We also recommend it in scripts and automation, because it keeps working if the Environment is renamed and lookups by ID are faster. You can get an Environment’s ID by running op environment list, by listing Environments with an SDK, or in the 1Password desktop app:
  1. Open and unlock the 1Password desktop app, then navigate to Developer > View Environments.
  2. Select View environment next to the Environment you want to fetch.
  3. Select Manage environment > Copy environment ID.

Access Environments with 1Password SDKs

With 1Password SDKs, you can read the secrets stored in your 1Password Environments by the Environment’s ID or name, and create, edit, and delete Environments and their secrets. See Manage Environments and secrets using 1Password SDKs for method details and examples in Go, JavaScript, and Python.
Service accounts can only use the Environments you grant them access to, and need write access to an Environment to manage its secrets. A service account can only edit or delete Environments it created.

Examples

Before running the following example:
  • Set OP_SERVICE_ACCOUNT_TOKEN to the token for a service account that has access to the Environment you want to fetch.
  • Set OP_ENVIRONMENT_ID to the ID of your 1Password Environment.

Secret visibility

Two settings control whether you get a secret’s value. One is stored with the secret, and the other is chosen for each request.
  • Hide value by default is a setting on the secret. In 1Password SDKs, it’s the concealed property. New secrets are hidden by default.
  • Reveal is a request option. In 1Password SDKs, it’s the reveal argument to get_secret() and list_secrets(). In 1Password CLI, it’s the --reveal flag. It doesn’t change the secret.
To change a secret’s default visibility, edit the secret with an SDK, or use the 1Password desktop app:
  1. Open and unlock the 1Password desktop app, then navigate to Developer > View Environments.
  2. Open the Environment and select Edit.
  3. Select the vertical ellipsis next to the secret, then select Show value by default or Hide value by default.

Access Environments with 1Password CLI

With 1Password CLI, you can: See Manage Environments and secrets for the commands and examples.
Service accounts can only use the Environments you grant them access to, and need write access to an Environment to manage its secrets. A service account can only edit or delete Environments it created.

Before you get started

Before you get started, install 1Password CLI version 2.43.0 or later. Then choose your authentication method:
  • Local authentication with the 1Password desktop app: Authenticate in the same way you unlock your 1Password desktop app, like with biometrics or your 1Password account password. To set up local authentication, turn on the 1Password CLI desktop app integration.
  • Service account: Authenticate using a service account token that has limited access to a singular Environment. To authenticate using a service account token, create a new service account with read access to the appropriate Environments. Choose read access to list secrets, or write access to manage them. Then export your service account token:

Pass secrets to an application or script

op run --environment is available in the stable release of 1Password CLI, version 2.41.0 or later. To pass secrets from a 1Password Environment to an application or script as environment variables, use op run with the --environment flag and the Environment’s ID, then pass the results to the application or script. 1Password CLI runs the application or script as a subprocess with your secrets loaded into the environment for the duration of the process.
Hidden secrets are automatically concealed in stdout and stderr output. To show them, change the secret’s default visibility or use the --no-masking flag with op run. See Secret visibility.

Use with environment variables from multiple sources

You can also use op run with multiple environments, or in combination with .env files or shell environment variables. When the same environment variable exists in multiple sources, 1Password CLI gives them the following precedence:
  1. 1Password Environments (highest priority)
  2. Environment files
  3. Shell environment variables (lowest priorities)
If a secret with the same name exists in multiple 1Password Environments, the last Environment specified takes precedence.

Examples

To print a single secret from a 1Password Environment, pass its name to printenv. Because Environment secrets are hidden by default, the value stays concealed in the output:
To run a script provisioned with the secrets from an Environment:
To list the secrets in an Environment as a .env file you can pipe to other tools, use op environment secret list with the --reveal flag:

Learn more