Skip to the page

Learn · Agent access

Agent access & grants

An agent calls Napalm with a service key, a person’s consent or its own grants, and never runs as a database superuser.

Agent credentials#

Every agent authenticates with one of three credentials, and the compiled access rules in dbschema/default.gel govern every row that credential can read or mutate.

The agent holdsYour schema seesAllowed access
A service key (ndb_…)No global caller. The branch’s serviceGlobals plus any globals the key carries.Allowed accessReads and writes rows permitted by your service rules. A --read-only key cannot write. A key made with --allow-query calls only the deployed queries listed. A key made with --call-budget makes at most that many calls in each hour or day.
A person’s consentglobal caller is the person. global ext::napalm::ClientTokenAgentGrant is the person’s grant. The branch’s userGlobals plus any globals the person set at consent.Allowed accessActs within the person’s access until the grant expires, or reads only when approved as read-only. When your consent page offers query or rate limits, the grant restricts the agent to the chosen deployed queries and call budget. Schema rules can read the grant to narrow access further.
A sign-in for the agentglobal caller is the agent’s own ext::auth::Identity.Allowed accessReaches nothing until a row grants that identity permission.

Use a read-only service key for your own coding or reporting agent. Use a person’s consent when one of your users connects an outside assistant such as Claude or ChatGPT. Give an agent a separate sign-in when a user delegates a specific subset of records to an unattended agent.

Grants as rows in your schema#

Access rules walk links across your types, so agent delegation is just one more object type in your schema.

Owner-bounded delegation
An owner can delegate only records that owner is already permitted to read.
Named records and deadline
Each grant links specific records and an expiration timestamp enforced on every read.
Revoked on delete
Deleting the grant row cuts off the next statement and evicts open live subscriptions.

In the example below, an AgentGrant opens selected notes to an agent’s identity until an exact deadline.

dbschema/default.gel
using extension auth;using extension napalm;using future simple_scoping; module default {  global caller := global ext::auth::ClientTokenIdentity;   # Client queries cannot reference ext::auth types directly, so this helper resolves an Identity by UUID.  function identity_by_id(target: uuid) -> optional ext::auth::Identity    using (select ext::auth::Identity filter .id = target);   type Person {    required identity: ext::auth::Identity {      constraint exclusive;    };    required name: str;     access policy self_has_full_access      allow all      using (.identity ?= global caller);  }   type AgentGrant {    required person: Person;    required agent: ext::auth::Identity;    multi notes: Note;    required expires: datetime;     access policy person_has_full_access      allow all      using (.person.identity ?= global caller);    access policy agent_can_see_its_own      allow select      using (.agent ?= global caller);  }   type Note {    required title: str;    required author: Person;     access policy author_has_full_access      allow all      using (.author.identity ?= global caller);    access policy granted_agent_can_read      allow select      using (exists (        select .<notes[is AgentGrant]        filter .agent ?= global caller          and .expires > datetime_of_statement()      ));  }}

Delegating notes to an agent is an ordinary insert linking the chosen records and expiration timestamp.

give.edgeql
insert AgentGrant {  person := (select Person filter .identity = global caller),  agent := identity_by_id(<uuid>$agent),  notes := (select Note filter .id in array_unpack(<array<uuid>>$notes)),  expires := datetime_of_statement() + <duration>'168 hours',}

Narrow grants#

Grant rows and OAuth consent tokens let you constrain an agent across records, operations, time and callable tools without relying on prompt instructions.

Scoped agent grants

Grants restrict agents by linked rows, expiry, read-only mode and allowed tools.

Eight schema and consent controls bound each delegated agent’s reach and call volume.

Which records
The grant’s notes link lists the delegated records, so the agent never sees the owner’s other notes.
Which operations
The rule above allows select only. To let an agent edit, add a can_edit field to the grant and a separate allow update rule that reads that field.
Until when
The rule compares expires against datetime_of_statement(), so an expired grant stops matching immediately without a cleanup job.
Reading only
Napalm refuses every write from a --read-only key or a read-only consent before the statement runs.
Which tools
Your consent page can read the available agent queries from GET /sign-in/agents/request using the user’s session (excluding queries hidden from agents) and pass the user’s selection as allowedQueries to POST /sign-in/agents/allow. The grant stores the list in allowed_queries and exposes only those tools. Calling any other deployed query returns 403 forbidden, ad-hoc statements return 403 deployed_query_required and no route can widen a grant after consent.
Requested scope
An agent can request narrower permissions up front via the authorize request’s OAuth scope, such as database:read for read-only access or query:listNotes for a single deployed query. Approving users can only narrow those requested scopes. The resulting grant never includes an unrequested query or write access when the agent asked for read-only, and the token response’s scope reports the granted permissions. OAuth scopes never set schema globals, so only the user on your consent page can pick a workspace, project, folder or tenant.
How often
Your consent page can pass callBudget (such as {"calls": 1000, "period": "hour"}) to cap the agent’s calls per UTC hour or day, stored on the grant as call_budget and call_budget_period. Calls past the budget fail with JSON-RPC error -32029 (call_budget_reached) and report when the next period starts. Both the console’s Agent grants section and napalm grants ls show current usage against the budget. See Limits.
Reading only in the schema
To enforce read-only in your rules as well, add deny insert, update, delete using ((global ext::napalm::ClientTokenAgentGrant).is_read_only ?= true).

Scoping grants with consent globals#

When a user has access to several workspaces, projects, folders or tenants in your app, setting a consent global scopes the agent grant to the single boundary chosen on your consent screen. The grant stores that global for its lifetime and overlays the branch’s userGlobals while running each call as the approving user. Service-key globals pin a backend key to one customer or scope the same way. See Service keys for one organization’s servers.

Follow four steps to wire a consent global into your schema and consent screen.

  1. Add a deny rule that reads the global

    In this workspace example, the allow rule admits members of the ticket’s organization as usual. When a grant sets current_org, the deny rule blocks tickets from every other organization. The same pattern scopes grants to a chosen current_workspace, current_project or current_folder. Without current_org, the deny rule does nothing and the user sees tickets across all of their organizations. Naming an organization the user does not belong to returns zero tickets because the allow rule never matched.

    dbschema/default.gel
    # Scope global chosen on the consent screen (for example, one workspace or organization)global current_org: str; type Ticket {  required org: Organization;  required title: str;   # Members can read tickets in their organizations  access policy member_can_read    allow select    using ((global caller in .org.members.identity) ?? false);   # A consent grant carrying current_org cannot access any other organization  access policy chosen_org    deny all    using ((<str>.org.id != global current_org) ?? false);}
  2. Allowlist the consent global

    Allowlist each global a user may set at consent with --grant-global on napalm endpoint or under Grant globals in the console’s Application access settings. Grants accept no globals until allowlisted, and removing a global from the allowlist disables existing grants carrying that global until re-authorized.

    Terminal
    # Allow users to bind default::current_org when approving an agent grantnapalm endpoint notes --grant-global default::current_org
  3. Send the global from your consent page

    Read the allowlisted grantGlobals from GET /sign-in/agents/request using the user’s session, let the user pick a workspace, project, folder or organization on your consent screen and pass globals in your POST /sign-in/agents/allow payload. Unlisted global names fail with 400 invalid_request, and agents cannot request globals via OAuth scope.

    Consent page
    // Pass the workspace, project, folder or organization selected on your consent screenconst answer = await fetch('https://notes.napalmdata.com/sign-in/agents/allow', {  method: 'POST',  headers: { Authorization: `Bearer ${session}`, 'Content-Type': 'application/json' },  body: JSON.stringify({    request,    isReadOnly: true,    days: 30,    globals: { 'default::current_org': organization.id },  }),})location.href = (await answer.json()).redirectTo
  4. Verify reach for the global and grant

    Because a service key has no global caller, running napalm keys reach --new with current_org verifies that the global alone opens zero tickets. In napalm test, assert the same invariant using { key: { globals: { default::current_org: <organization id> } } } with reach: Ticket and expect: { count: 0 }. Test an agent’s grant covers testing the combined user and grant rule.

    Run napalm grants reach to count a stored grant’s live reach as its approving user with the grant’s globals and read-only mode applied. A grant scoped to Acme sees only Acme’s tickets.

    Terminal
    # Service key with current_org but no user identity reaches 0 ticketsnapalm keys reach notes --new --read-only --global default::current_org=<organization id> # Stored user grant with current_org reaches only that organization's ticketsnapalm grants reach notes <grant id>

Prompt injection#

An agent connected over MCP or A2A reaches your project’s data. The schema stays hidden unless you enable napalm endpoint --share-schema, and on connection the server instructs the client that database rows are data rather than instructions.

Policies block prompt injection

Hostile text inside a row never widens the caller’s permitted rows.

Compiled access policies enforce the real boundary. A row containing “fetch everyone’s notes” never widens global caller or the rows that caller may read. Set --passthrough none to reject ad-hoc statements and restrict the agent strictly to deployed queries and actions. See Tools for agents.

Audit log and change log#

Declare a schema trigger to write an immutable audit entry inside the same transaction as every mutation, so no write from any caller commits without a provenance row.

Transactional audit trail

Schema triggers log the caller at commit alongside protocol change-log metadata.

Every write to a watched type inserts an AuditEntry row in the same SQL transaction.

dbschema/default.gel
using extension auth;using extension napalm;using future simple_scoping; module default {  global caller := global ext::auth::ClientTokenIdentity;   type Note {    required title: str;    owner: ext::auth::Identity;     access policy owner_has_full_access      allow all      using (.owner ?= global caller);     trigger record_change after insert, update for each do (      insert Change {        note := __new__,        changed_by := global caller,        title := __new__.title,      }    );  }   type Change {    required note: Note;    changed_by: ext::auth::Identity;    required title: str;    required at: datetime {      default := datetime_of_statement();    };     access policy note_owner_can_read      allow select      using (.note.owner ?= global caller);    access policy callers_record_as_themselves      allow insert      using (.changed_by ?= global caller);  }}

The branch’s change log also records each commit’s caller kind and protocol source (http, mcp or a2a). Inspect recent commits with napalm changes. Watching and stopping an agent covers live inspection and kill switches.

Revocation#

Deleting a grant cuts off the agent’s access by its very next statement and evicts restricted rows from open live streams. Deleting either a custom grant row or a built-in ext::napalm::AgentGrant row from OAuth consent takes effect immediately.

revoke.edgeql
delete AgentGrantfilter .agent.id = <uuid>$agent

Because API statements cannot reference ext::napalm::AgentGrant directly unless enabled, expose a schema alias when users manage OAuth grants inside your app, as Watching and stopping an agent shows. Revoke a service key with napalm keys revoke, or halt all external traffic immediately with napalm endpoint --disable.

Project managers can inspect and revoke grants across every branch in the console’s project overview (under Agent grants), via napalm grants ls and napalm grants revoke, or at GET /projects/{id}/agent-grants and POST /projects/{id}/agent-grants/{grant}/revoke. Each entry shows the agent, approving user, write mode, allowed queries, globals, expiry and last call. Once revoked, the agent’s next call fails with 401 invalid_token until the user re-approves access on your consent page. Managers can also audit a live grant’s exact row reach with Reach in the console, napalm grants reach or GET /projects/{id}/agent-grants/{grant}/reach.

Type a word or two to search every docs page.