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 fetch. 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
To fetch secrets from a 1Password Environment, you’ll need its unique identifier (ID). You can get an Environment’s ID in the 1Password desktop app:- Open and unlock the 1Password desktop app, then navigate to Developer > View Environments.
- Select View environment next to the Environment you want to fetch.
- Select Manage environment > Copy environment ID.
Read Environments with 1Password SDKs
Get secrets
With 1Password SDKs, you can retrieve the secrets stored in your 1Password Environments using theget_variables() function with the Environment’s ID.
GetVariablesResponse object that contains a list of the secrets stored in the Environment.
EnvironmentVariable object that contains the secret’s name (for example, DB_HOST), value, and whether the value is hidden by default.
By default, secrets in 1Password Environments have “Hide value by default” turned on. To change this, open an Environment, select the vertical ellipsis next to the secret, then select Show value by default.
Examples
- Service account
- 1Password desktop app
Before running the following example:
- Set
OP_SERVICE_ACCOUNT_TOKENto the token for a service account that has access to the Environment you want to fetch. - Set
OP_ENVIRONMENT_IDto the ID for your 1Password Environment.
Read Environments with 1Password CLI
With 1Password CLI, you can pass the secrets stored in your 1Password Environments to an application or script usingop run --environment. You can also retrieve them from your 1Password Environments with op environment read (beta).
Before you get started
Before you get started, install 1Password CLI. To useop environment read, you’ll need the latest beta build of 1Password CLI, version 2.33.0-beta.02 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 can only access the Environments you want to fetch. To authenticate using a service account token, create a new service account with read access to the appropriate Environments. 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.
By default, secrets in 1Password Environments have “Hide value by default” turned on. Hidden secrets are automatically concealed in stdout and stderr output. To change this, open an Environment, select the vertical ellipsis next to the secret, then select Show value by default. Or use the
--no-masking flag with op run.Use with environment variables from multiple sources
You can also useop 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:
- 1Password Environments (highest priority)
- Environment files
- Shell environment variables (lowest priorities)
Examples
To print a single secret from a 1Password Environment, pass its name toprintenv. Because Environment secrets are hidden by default, the value stays concealed in the output:
Get secrets (beta)
Beta feature
op environment read is available in the latest beta build of 1Password CLI, version 2.33.0-beta.02 or later.op environment read with the Environment’s ID. 1Password CLI will return a list of the secrets in the Environment formatted as key-value pairs.
Examples
To get the secrets for a local development Environment with the IDblgexucrwfr2dtsxe2q4uu7dp4: