# Overview

Canonical URL: https://developers.iagenify.com/sdk/agent/permissions/
Language: en

One callback, called only when the mode does not already answer. It receives the tool, its category and its actual arguments, and it answers once, always or deny.

Status: onPermission · 3 answers · the arguments are there

Permission is not a policy file and not a remote setting. It is a function in your process, called with everything needed to decide — which is why it can say yes to `write` under `src/` and no everywhere else.

## The callback {#callback}

```javascript
const agent = api.agents.create({
  runtime: "local",
  machine: pc,
  model: "gemini-3.5-flash",
  mode: "ask",
  onPermission: async ({ id, tool, category, args, mode }) => {
    if (category === "exec") return "deny";
    if (tool === "write" && args.path.startsWith("src/")) return "always";
    return "once";
  },
});
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | The tool call's identifier. The same one carried by `tool_start` and `tool_end`. |
| `tool` | string |  | The tool's name, e.g. `write`, `bash`, `write_storage`. |
| `category` | string |  | One of the [ten](/sdk/agent/permissions/categories). Six tools compute it from their arguments. |
| `args` | object |  | What the model actually asked for — the path, the command, the filter, the key. |
| `mode` | string |  | The mode in force at this moment. |

## The three answers {#answers}

| Return | Means |
| --- | --- |
| `"once"` or `true` | Allow this call. |
| `"always"` | Allow it, and do not ask again — see [Persistence](/sdk/agent/permissions/persistence) for what that covers. |
| `"deny"`, `false`, `null` or nothing | Refuse. The tool returns « Refused by the user. » and the loop continues. |

> **A refusal is not an error**
>
> It goes back to the model as a failed tool result, and the agent is told not to retry a refused tool but to adapt or explain. So denying is a normal way to steer a run, not a way to break it.

## The order things are decided in {#order}

- `read`, `memory` and `task` are allowed outright. The callback is not called.
- In [plan](/sdk/agent/modes/plan) mode, everything else is refused outright. The callback is not called.
- [`send`, `publish`, `money`](/sdk/agent/permissions/always-ask) go to the callback — in every mode, every time.
- In [full](/sdk/agent/modes/full) mode, everything else is allowed.
- A remembered « always » for this call is honoured.
- In [auto](/sdk/agent/modes/auto), `write` is allowed.
- Otherwise the callback is called.

## It is announced both ways {#events}

```javascript
onEvent: (e) => {
  if (e.type === "permission")        console.log("asking", e.tool, e.category, e.args);
  if (e.type === "permission_result") console.log("answered", e.decision);   // "once" | "always" | "deny"
}
```

The `permission` event is emitted before your callback is awaited, so an interface can show the prompt while the promise is pending — which is exactly how a human-in-the-loop UI is built: the event paints the dialog, the promise resolves when a button is clicked.

## Without a callback {#no-callback}

Anything that would be asked is refused, with a message saying it needs approval and that no one can approve it. An agent with no `onPermission` is therefore close to read-only, whatever its mode.

## Subagents go through the same one {#subagents}

A subagent's tools reach the parent's callback, with the parent's mode. Delegating is not a way around a permission — `task` itself is free precisely because everything inside it is not.

- [The ten categories](/sdk/agent/permissions/categories): The matrix, and the tools that compute theirs.
- [Always asked](/sdk/agent/permissions/always-ask): The three a mode cannot open.
- [Persistence](/sdk/agent/permissions/persistence): Where an « always » is kept, and for how long.

```python
def on_permission(request):
    # request: {"id", "tool", "category", "args", "mode"}
    if request["category"] == "exec":
        return "deny"
    if request["tool"] == "write" and request["args"].get("path", "").startswith("src/"):
        return "always"
    return "once"

agent = api.agents.create(
    runtime="local",
    machine=pc,
    model="gemini-3.5-flash",
    mode="ask",
    on_permission=on_permission,
)
```

```python
def on_event(event):
    if event["type"] == "permission":
        print("asking", event["tool"], event["category"], event["args"])
    if event["type"] == "permission_result":
        print("answered", event["decision"])   # "once" | "always" | "deny"
```
