> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ctrlrun.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# context

> Bind the principal for calls made inside the block.

`ctrlrun.context` — function, defined at `src/ctrlrun/control.py:140`

```python theme={null}
def context(agent: str, user: str | None) -> Iterator[None]
```

Bind the principal for calls made inside the block.

A protected function called outside any `context()` has no principal and is denied
(SPEC-v0.1 §2.1).

**`environment` was a parameter here until v0.3** and is gone (SPEC-v0.3 §2.5). A grant may
scope to an environment, which makes it an authorization input, and an authorization
dimension the subject sets is not one — the same argument that removes
`--principal-from-client-info` from the gateway. It is set once on the `Control` now, so
every Action a deployment proposes carries the deployment's own answer.

Where an `IdentityProvider` is installed, the principal named here is a **hint** rather than
an identity: the provider wins where it answers (§3.2).

## Next

* [Python API index](/reference/api/index).
* [Get started](/get-started/quickstart) · [Why](/why).


## Related topics

- [IdentityContext](/reference/api/IdentityContext.md)
- [Errors](/reference/errors.md)
- [Three ways in](/get-started/three-ways-in.md)
- [ApprovalRequired](/reference/api/ApprovalRequired.md)
- [OWASP Top 10 for Agentic Applications](/OWASP-AGENTIC-TOP10.md)
