# Chalk Compute Reference: Secret
source: https://docs.chalk.ai/compute-docs#section-secret

References to secrets available to a sandbox, container, or remote function.

Use `Secret.from_name(...)` to reference a secret by name; the secret value is resolved at runtime from the Chalk secret store and injected as an environment variable.

## `Secret`
source: https://docs.chalk.ai/compute-docs#Secret

Class

A reference to a Chalk secret or integration to inject as env vars.

Construct instances via the factory methods rather than instantiating directly.

**Examples**

```python
Secret.from_chalk_env("OPENAI_API_TOKEN")
Secret.from_chalk_integration("prod_postgres")
Secret.from_local_env("OPENAI_API_KEY")
Secret.from_local_env("OPENAI_API_KEY", env_var_name="API_KEY")
Secret.from_local_env_file(".env")
```

**Attributes**

- `is_lazy`: `bool`
  Whether this secret requires local resolution before container start.

  **Returns**

  bool [`True`](https://docs.python.org/3/library/constants.html#True) if the secret is built from a local env var or env file.

### `Secret.from_chalk_env(name, alias, prefix)`
source: https://docs.chalk.ai/compute-docs#Secret.from_chalk_env

Reference a standalone secret by name (e.g. `"OPENAI_API_TOKEN"`).

The secret's value is injected as an environment variable with the same name, unless `alias` or `prefix` is given.

**Parameters**

- `name`: `str`
  Name of the Chalk secret.
- `alias`: `str | None` = `None`
  Rename the env var exposed in the container.
- `prefix`: `str | None` = `None`
  Optional prefix applied to the env var name.

**Returns**

`Secret`

A secret reference.

### `Secret.from_chalk_integration(name, keys, aliases, prefix)`
source: https://docs.chalk.ai/compute-docs#Secret.from_chalk_integration

Reference an integration by name (e.g. `"prod_postgres"`).

All secrets associated with the integration are injected as env vars.

**Parameters**

- `name`: `str`
  Name of the Chalk integration.
- `keys`: `list[str] | None` = `None`
  Limit injection to the listed keys.
- `aliases`: `dict[str, str] | None` = `None`
  Rename specific keys when exposing them as env vars.
- `prefix`: `str | None` = `None`
  Optional prefix applied to every injected env var.

**Returns**

`Secret`

A secret reference bound to the named integration.

### `Secret.from_env(name, alias, prefix)`
source: https://docs.chalk.ai/compute-docs#Secret.from_env

Deprecated alias for `from_chalk_env`.

.. deprecated:: Use `from_chalk_env` instead.

### `Secret.from_integration(name, keys, aliases, prefix)`
source: https://docs.chalk.ai/compute-docs#Secret.from_integration

Deprecated alias for `from_chalk_integration`.

.. deprecated:: Use `from_chalk_integration` instead.

### `Secret.from_local_env(local_env_var, env_var_name)`
source: https://docs.chalk.ai/compute-docs#Secret.from_local_env

Inject a local environment variable as a secret into the container.

Reads `os.environ[local_env_var]` at container start time, upserts it as a Chalk secret, and injects it as an env var in the container.

**Parameters**

- `local_env_var`: `str`
  Name of the local environment variable to read.
- `env_var_name`: `str | None` = `None`
  Name for the env var inside the container. Defaults to `local_env_var`.

**Returns**

`Secret`

A lazy secret reference resolved at `Container.run()` time.

### `Secret.from_local_env_file(path)`
source: https://docs.chalk.ai/compute-docs#Secret.from_local_env_file

Inject all variables from a local `.env` file as secrets.

Reads the file at container start time, upserts each `KEY=VALUE` pair as a Chalk secret, and injects them as env vars in the container. Lines starting with `#` and blank lines are ignored.

**Parameters**

- `path`: `str`
  Path to the local `.env` file.

**Returns**

`Secret`

A lazy secret reference resolved at `Container.run()` time.
