Agents, people, and keys
Decide who can read, send, and administer a mailbox, and confine agents with mailbox-scoped keys and namespaces.
Every action on a mailbox is taken by a principal, and Samva records which one. A principal is a person with a grant, a mailbox-scoped key, or an agent that handles its events. Each principal reaches only the mailboxes you give it, and none can do more than the person behind it.
People and grants
A grant shares one shared mailbox with one organization member. It carries a role. The
person who creates a mailbox receives an admin grant.
| Role | Reads the mailbox | Edits threads, labels, drafts, and notes | Sends and replies | Approves sends, reads and discards held malware, configures the mailbox |
|---|---|---|---|---|
viewer | Yes | No | No | No |
collaborator | Yes | Yes | Yes | No |
admin | Yes | Yes | Yes | Yes |
Decision rules can hold a person's sends for another person to review. Set a mailbox rule matching that member, or a floor that applies to every sender. See Approve sends.
Managing grants needs admin. Grant a member access with POST /v1/mailboxes/{id}/grants:
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const grant = await samva.mailboxes.createGrant({
id: "mbx_...",
userId: "user_...",
role: "collaborator",
});curl -X POST https://api.samva.dev/v1/mailboxes/$MAILBOX_ID/grants \
-H "X-API-Key: $SAMVA_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "userId": "user_...", "role": "collaborator" }'The member must already belong to the organization; anyone else is a validation error. Granting
someone who already holds a grant is a 409, so granting never widens access by accident. Change an
existing grant instead:
await samva.mailboxes.updateGrant({
id: "mbx_...",
grantId: grant.id,
role: "admin",
});PATCH /v1/mailboxes/{id}/grants/{grantId} takes role. The change applies to the person's next
request on every surface. DELETE on the same path revokes the grant.
A mailbox always keeps at least one admin. Revoking the last one, or changing its role, is a 409:
hand the mailbox to a teammate first.
A personal mailbox has one human owner. Another person cannot receive a grant to it, even if they are an organization owner or admin. Only the personal owner can configure its access; the owner may authorize agents and keys within their own permissions.
Mailbox-scoped keys
An agent should not hold a key that reaches your whole organization. Create a restricted key with
mailboxes access instead. The key acts as itself, named by the key's name, so every message it
sends and every thread it changes is attributed to that key. A full-access key has no identity of its
own: it acts as its owner.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });
const key = await samva.apiKeys.create({
name: "Support agent",
access: {
mode: "restricted",
resources: {},
mailboxes: {
permissions: ["read", "send"],
mailboxIds: ["mbx_..."],
},
},
});From the CLI, the same key is samva api-keys create --name "Support agent" --mailbox-permission read --mailbox-permission send --mailbox mbx_...; add --namespace ns_... to confine the key.
Set a policy on the key to hold sends for review.
| Field | Meaning |
|---|---|
permissions | One or more of read, update, send, spam.read. |
mailboxIds | Limits the key to these mailbox IDs. Omit it for shared mailboxes its owner reaches. |
namespaceId | On access, confines the key to one namespace. |
For a personal mailbox, the owner must explicitly include its ID in mailboxIds. A delegated key
with no mailbox list reaches shared mailboxes only. Organization-level message tools do not expose
personal messages, even when the key belongs to the personal owner; use mailbox-scoped tools.
| Permission | Lets the key |
|---|---|
read | Read mailboxes, threads, messages, attachments, and the mailbox's actions and events. |
update | Change thread state, labels, drafts, and notes. |
send | Send, reply, reply to all, forward, and send drafts. |
spam.read | List held messages as metadata. |
A key is capped by the member who owns it. It reaches only mailboxes that member reaches, with at most
that member's current role, and it stops working if the member leaves the organization. A restricted
key with mailboxes access cannot create, configure, pause, or delete a mailbox or manage grants;
a full-access key acts as its owner and can, which is why setup uses one. No key, full-access or
restricted, can approve or deny a send or release or discard held mail: those need a person signed
in. A key scoped to listed mailboxes holds mailbox access only. A key confined to a namespace also reaches
that namespace's other resources.
Revoke a key with POST /v1/api-keys/{id}/revoke. It stops authenticating at once, on every surface, and
the mail it handled keeps its attribution. Deleting a mailbox removes it from every key scope and
webhook filter that named it, and a key or endpoint left with no mailbox is disabled.
Hold a key's actions for review
A key's permitted sends run directly unless a policy requires review. To hold sends and replies,
set a write rule without issuing a new key. Use an organization owner or admin's OAuth token;
API keys cannot change policies, even when they have full access:
import { createClient } from "samva";
const samva = createClient({
authToken: process.env.SAMVA_AUTH_TOKEN!,
orgSlug: process.env.SAMVA_ORG_SLUG!,
});
const current = await samva.policies.getPolicy({ kind: "apiKey", id: "key_..." });
await samva.policies.setPolicy({
kind: "apiKey",
id: "key_...",
ifVersion: current.version,
presets: [],
rules: [{ match: { effect: "write" }, decide: "person" }],
});From the CLI, sign in with samva login, then use
env -u SAMVA_API_KEY samva --org <slug> policies set apiKey key_... --if-version <observed-version> --data
with the same configuration JSON. Removing SAMVA_API_KEY for the command lets it use the person's signed-in session.
Read the policy snapshot's version before editing and pass it as ifVersion. The example
replaces the full policy, so preserve existing rules, presets, and instructions you need. An unset
policy has version 0. On 409, reload and review the snapshot before replacing it; never retry
stale configuration with a newer version. See Policy versions.
Sends and replies have effect write; a rule for final alone does not hold them.
The change applies to the key's next action. A mailbox or organization floor can still hold or
refuse an action even when the key's own policy allows it.
Namespaces
A namespace is a sub-tenant inside your organization, one per customer when you resell mailboxes or
run agents on behalf of customers. A mailbox belongs to a namespace when you create it with
namespaceId, and a key created with access.namespaceId reaches only that namespace's mailboxes,
so one customer's agent can never read another's mail. Webhook endpoints take the same namespaceId
filter; an endpoint that names both mailboxIds and namespaceId accepts only mailboxes inside that
namespace.
A namespace also holds domains, senders, contacts, and templates, and a confined key reaches those too. The Namespaces guide covers creating namespaces, confining keys, sends, moving resources, usage, and deletion. A mailbox keeps the namespace it was created with.