Configure permissions
Permissions decide whether the agent can run a tool now, must ask first, or is blocked entirely. The SDK exposes a mode at session start, granular allow and deny lists, runtime overrides, and a per-request response API.
Permission modes
Set the mode when the SDK starts. The mode applies to every tool call until you change it.
- interactive (default): emit
permission_requestevents and wait for your code to allow or deny. - unrestricted: allow every tool call without prompting. Use only inside a sandbox.
- restricted: deny risky tools automatically. Reads still pass through.
- external: hand the decision to a configured callback or hook.
Legacy aliases like default and bypassPermissions still work, but new code should use the names above.
Set the mode at session start
Pass the mode into the SDK constructor. The default is interactive, which is the safest choice for any agent that runs untrusted prompts.
import { AutohandSDK } from '@autohandai/agent-sdk';
const sdk = new AutohandSDK({
cwd: '.',
permissionMode: 'interactive',
});
await sdk.start();from autohand_sdk import AutohandSDK
async with AutohandSDK(
cwd=".",
permission_mode="interactive",
) as sdk:
...package main
import (
"context"
autohand "github.com/autohandai/code-agent-sdk-go"
)
ctx := context.Background()
sdk := autohand.NewSDK(&autohand.Config{
CWD: ".",
PermissionMode: autohand.PermissionInteractive,
})
_ = sdk.Start(ctx)
defer sdk.Close()import AgentSDK
let manager = PermissionManager(
hookManager: HookManager(),
mode: .ask
)
Runner.setPermissionManager(manager)import ai.autohand.sdk.sdk.AutohandSDK;
import ai.autohand.sdk.types.SDKConfig;
import ai.autohand.sdk.types.PermissionMode;
var sdk = new AutohandSDK(SDKConfig.builder().cwd(".").build());
sdk.start();
sdk.setPermissionMode(PermissionMode.INTERACTIVE);Respond to permission requests
In interactive mode the SDK emits a permission_request event whenever the agent reaches a guarded tool. Your code decides what to do, then calls back with allowed and an optional remember scope.
for await (const event of sdk.streamPrompt({
message: 'Run the test suite and report failures.'
})) {
if (event.type === 'permission_request') {
const allowReads = event.tool === 'read_file' || event.tool === 'git_status';
await sdk.permissionResponse({
requestId: event.requestId,
allowed: allowReads,
remember: allowReads,
});
continue;
}
if (event.type === 'message_update') {
process.stdout.write(event.delta);
}
}async for event in sdk.stream_prompt("Run the test suite and report failures."):
if event["type"] == "permission_request":
tool = event.get("tool", "")
allow_reads = tool in ("read_file", "git_status")
await sdk.respond_to_permission(
event["request_id"],
decision="allow" if allow_reads else "deny",
allowed=allow_reads,
remember=allow_reads,
)
continue
if event["type"] == "message_update":
print(event.get("delta", ""), end="")events, _ := sdk.StreamPrompt(ctx, &autohand.PromptParams{
Message: "Run the test suite and report failures.",
})
for event := range events {
switch e := event.(type) {
case autohand.PermissionRequestEvent:
allow := e.Tool == "read_file" || e.Tool == "git_status"
scope := autohand.ScopeOnce
if allow {
scope = autohand.ScopeSession
}
_ = sdk.PermissionResponse(ctx, e.RequestID, allow, scope)
case autohand.MessageUpdateEvent:
fmt.Print(e.Delta)
}
}let stream = Runner.runStream(
agent: agent,
prompt: "Run the test suite and report failures."
)
for try await event in stream {
if event.type == .content, let data = event.data {
print(data, terminator: "")
}
}sdk.streamPrompt(
new PromptParams("Run the test suite and report failures."),
event -> {
if (event instanceof Events.PermissionRequestEvent pre) {
boolean allowReads = pre.tool().equals("read_file");
if (allowReads) {
sdk.allowPermission(pre.requestId(), DecisionScope.SESSION);
} else {
sdk.denyPermission(pre.requestId(), DecisionScope.ONCE);
}
} else if (event instanceof Events.MessageUpdateEvent mue) {
System.out.print(mue.delta());
}
}
);Use the ergonomic helpers when they read better than permissionResponse:
await sdk.allowPermission(event.requestId, 'session');
await sdk.denyPermission(event.requestId, 'once');
await sdk.suggestPermissionAlternative(
event.requestId,
'Run bun run typecheck before bun run build.'
);await sdk.allow_permission(event["request_id"], scope="session")
await sdk.deny_permission(event["request_id"], scope="once")
await sdk.suggest_permission_alternative(
event["request_id"],
"Run bun run typecheck before bun run build.",
)Allow and deny lists
Use allowedTools and disallowedTools at startup to filter the tools the CLI offers and authorizes. Denials take precedence. For example, this host permits reading files and inspecting Git status.
const sdk = new AutohandSDK({
allowedTools: ['read_file', 'git_status'],
disallowedTools: ['delete_path', 'run_command'],
});
For Python, Go, and Java examples, see Restrict the tool surface.
Yolo patterns for unattended runs
For headless or batch jobs, set a yolo pattern that auto-approves whitelisted tools and expires after a timeout.
const sdk = new AutohandSDK({
cwd: '.',
yolo: 'allow:read,write',
yoloTimeout: 60, // seconds
});sdk = AutohandSDK(
cwd=".",
yolo="allow:read,write",
yolo_timeout=60,
)Change the mode at runtime
CLI-backed SDKs can change the mode of an active session through autohand.permissionModeSet. In TypeScript, call setPermissionMode on the running SDK.
await sdk.setPermissionMode('unrestricted');
// later
await sdk.setPermissionMode('interactive');
Best practices
- Default to
interactivemode in any agent that accepts untrusted prompts. - Show the tool name, description, and working directory in your approval UI so reviewers can decide quickly.
- Auto-allow read-only tools and ask before shell or write operations unless the run is inside a sandbox.
- Pair
unrestrictedmode with ayoloTimeoutso a forgotten run cannot keep approving forever. - Log every allow or deny decision when the run is part of CI, audit, or customer support flows.