# Sharing and permissions

Source: https://docs.autessa.com/docs/autessascript/guides/sharing-permissions

> How access works: company roles, per-resource access levels, sharing, and AutessaDB row/column security — and what the SDK deliberately does not expose.

# Sharing and permissions

How access works: company roles, per-resource access levels, sharing, and AutessaDB row/column security — and what the SDK deliberately does not expose.

**The decision:** you built something. Who can see it, edit it, or run it — and how do you
control that from a script?

## The layers

- **Company roles.** Every member holds a role in the company. There are six built-in roles;
  **"User" is the base role** granted on auto-join. List them with `autessa.company.roles`.
  Roles gate what a member can do at the company level.
- **Per-resource access levels.** Resources (agents, tools, tables, connectors, apps,
  scheduled events, e-signature templates, …) are shared at an access level: **READ**,
  **WRITE**, **PUBLISH**, or **ADMIN**, in increasing power. Most resource namespaces expose a
  matching pair — a `getSharingDetails` to see who has what, and a `share` to grant or change
  it, e.g. `autessa.autessadb.tables.getSharingDetails` and `autessa.autessadb.tables.share`.
- **AutessaDB row/column security (RLS/FLS).** Within a table, roles decide which *rows* a
  user sees and which *columns* are masked. Table security is **default-open**: a table with
  no role rules is fully visible, and a masked column needs an explicit role rule to hide it.
  Manage table roles with `autessa.autessadb.roles.create`, `.update`, and `.list`. Every
  query runs under an *acting identity*, which is what the row/column rules are evaluated
  against. Rules can target people, teams, company roles, everyone at the company, apps, and
  API keys — see *row and column security* in the AutessaDB API reference.

## Who a run acts as

Tools, agents, multi-agents, and scripts **run as the person who started them**. A script that
reads a table sees exactly the rows and columns that person sees, and a tool or agent it calls
runs as that same person. Nothing a run passes along — environment variables, arguments, or
tool inputs — can change who it runs as.

- **Started by a person** (builder, CLI, an app in the default hosting mode): runs as that
  person.
- **Started by an API key**: runs with the key's limits, which are never more than the key's
  owner can reach. See the *API keys* guide.
- **Started by a visitor of a public or sign-in app**: runs as that visitor, limited to the
  app's permissions and to what the person who saved them can reach.
- **Triggers, scheduled jobs, and webhook handlers**: run as the person who set them up. If that
  person is no longer a member of the company, the run fails with a message saying so.
- **Inbound messages** (Slack, text messages, inbound calls): run as the person who connected
  that channel.

Those limits follow the run everywhere: into sub-agents, tools called with
`tools.invokeById`, scripts, and analytics queries. A run started by an API key or an
app visitor can't use the CLI tool. Calling another tool or agent with
`tools.invokeById` or `agents.invoke` requires that the person the run acts as
has at least READ on it. For a key or app visitor, a call it makes directly must be in
its grants; tools, agents and tables reached from inside that run need only the access
of the person it's bounded by (the key's owner, or whoever last saved the app's
permissions).

### Run as owner

Sometimes a simple data tool should do something the people calling it can't do directly —
for example, let anyone file a request into a table they can't otherwise read. Set the tool's
**Run as** to **Owner** (`toolConfig.runAs: "OWNER"`) and it runs as you, limited to the one
table it is configured for.

- **Only simple AutessaDB data tools** — insert, update, delete, get, and aggregate tools whose
  table and columns are fixed in the tool's settings. Scripts, CLI tools, analytics queries,
  connectors, and any tool that takes a table or SQL from its caller can't run as their owner
  ("This kind of tool can't run as its owner.").
- **Only the owner can turn it on** ("Only the tool's owner can make it run as them.").
- **Only callable from my other tools** (`toolConfig.invokableBy: "OWNER_TOOLS"`) limits the
  tool to being called from another tool whose current published version you published, so
  nobody can call it directly.
- **It turns itself off** — back to running as the caller — when anyone other than the owner
  edits, publishes, or rolls back the tool, when ownership moves to someone else (including
  when the owner leaves the company), or when the tool is installed from a package. The tool
  shows why, and the new owner can turn it back on.

### Who sees run history

Tool history, trigger history, and conversations started through the API or an app hold the
results of reads made as a specific person, so they are as private as those reads. Each run is
visible to the person it ran as, to the tool's or agent's Admins, and to company Admins.
Listing tool history from a script follows the same rule.

## Decision rules

1. **Grant the least level that works.** READ to look, WRITE to edit rows/config, PUBLISH to
   publish a new version, ADMIN to manage sharing itself. Don't hand out ADMIN to let someone
   merely edit.
2. **Auto-join grants "User", never "Admin".** When wiring up membership, the base "User"
   role is the default; elevate deliberately.
3. **Table security is opt-in.** If a table holds sensitive rows or columns, add explicit role
   rules with `autessa.autessadb.roles.create` — otherwise it is open by default.
4. **Check before you assume.** Use the resource's `getSharingDetails` to read the current
   grants before changing them.
5. **You can't hand out more than you have.** Keys, app permissions, team grants, and company
   roles you assign are checked against your own access. Only Admins can assign the Admin role.
6. **Prefer running as the caller.** Use **Run as owner** only for a narrow data tool, ideally
   with **Only callable from my other tools**.

## Worked examples

**A. Share a table read-only with a team.** `autessa.autessadb.tables.share` at READ, then
confirm with `autessa.autessadb.tables.getSharingDetails`.

**B. Hide a salary column.** Add a table role via `autessa.autessadb.roles.create` that masks
the `salary` column for the base role, leaving it visible only to a privileged role — because
without a rule the column is open.

## What the SDK deliberately does NOT expose

Some administrative actions are intentionally out of scope for scripts — for example
transferring ownership of a resource is not a scriptable operation. Sharing and access-level
changes are scriptable; wholesale ownership transfer is not.

## See also

- *data-placement* — the tables these rules protect.
- *connectors* — connectors follow the same share/access-level model.

## Related

- [Autessa SDK overview](/docs/autessascript/sdk.md)

