---
title: Scope
description: The scope identifies who runs a function and where it runs.
---

A scope is app-defined data such as the actor, account, and locale. Put booking IDs and form data in the input.

<Diagram caption="Nested calls inherit the caller's scope, and listeners use the emitter's scope by default.">
  <Flow>
    <Node title="registry.as(scope)" subtitle="Binds the scope once" tone="accent" />
    <Fan>
      <Node slot="from" title="ctx.scope" subtitle="Available in each call" />
      <Node title="ctx.run" subtitle="Inherits the current scope" />
      <Node title="Listener" subtitle="Uses the emitter's scope" />
    </Fan>
  </Flow>
</Diagram>

```ts twoslash
import { init } from "logic-sdk";

type Scope = { accountId: string; actor: string | null; locale: string };
const { query, createRegistry } = init<{ scope: Scope }>();
const getLocale = query({ handler: async (ctx) => ctx.scope.locale });
const registry = createRegistry({ modules: { accounts: { getLocale } } });
// ---cut---
const caller = registry.as({ accountId: "a1", actor: null, locale: "es" });
await caller.run(getLocale);
```

- **Binding.** Bind once per request, script, or test. Use `CallerOf<typeof registry>` for helpers that take the caller.
- **Inheritance (1).** A nested call gets the caller's scope. To replace it, pass `{ scope }` as the third argument to `ctx.run`. The new scope is whole, not merged, and applies to that call and every call it runs.
- **Listeners (2).** See [Job scope](/docs/concepts/jobs#scope) for listener overrides and how `jobs.scope.load` rebuilds scope.

## The system

Use distinct scope variants for signed-out actors, signed-in actors, and system work. A system scope can carry `kind: "system"`, a `job` name, `actor: null`, and an account ID when needed.

Create system scopes in crons or trusted scripts. Grant system access explicitly in policies. Preserve the variant in [job scope](/docs/concepts/jobs#scope).

## See also

[Authorization](/docs/concepts/authorization), [Jobs](/docs/concepts/jobs), [Crons](/docs/concepts/crons)
