Permissions

Overview

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.

onPermission3 answersthe arguments are there
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

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

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";
  },
});
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,
)
idstring

The tool call's identifier. The same one carried by tool_start and tool_end.

toolstring

The tool's name, e.g. write, bash, write_storage.

categorystring

One of the ten. Six tools compute it from their arguments.

argsobject

What the model actually asked for — the path, the command, the filter, the key.

modestring

The mode in force at this moment.

The three answers

ReturnMeans
"once" or trueAllow this call.
"always"Allow it, and do not ask again — see Persistence for what that covers.
"deny", false, null or nothingRefuse. 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

  • read, memory and task are allowed outright. The callback is not called.
  • In plan mode, everything else is refused outright. The callback is not called.
  • send, publish, money go to the callback — in every mode, every time.
  • In full mode, everything else is allowed.
  • A remembered « always » for this call is honoured.
  • In auto, write is allowed.
  • Otherwise the callback is called.

It is announced both ways

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"
}
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"

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

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

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.