-
Notifications
You must be signed in to change notification settings - Fork 503
Open
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentation
Description
the Claude SDK docs example is misleading for can_use_tool with custom permission handler, the correct case lays on github repo.
WRONG
from claude_agent_sdk import query, ClaudeAgentOptions
async def can_use_tool(tool: str, input: dict) -> bool:
# Check if the model is requesting to bypass the sandbox
if tool == "Bash" and input.get("dangerouslyDisableSandbox"):
# The model wants to run this command outside the sandbox
print(f"Unsandboxed command requested: {input.get('command')}")
# Return True to allow, False to deny
return is_command_authorized(input.get("command"))
return True
async def main():
async for message in query(
prompt="Deploy my application",
options=ClaudeAgentOptions(
sandbox={
"enabled": True,
"allowUnsandboxedCommands": True # Model can request unsandboxed execution
},
permission_mode="default",
can_use_tool=can_use_tool
)
):
print(message)will result:
Error: Tool permission request failed: Error: Tool permission callback must return PermissionResult (PermissionResultAllow or PermissionResultDeny), got <class 'dict'>
The correct example is https://github.com/anthropics/claude-agent-sdk-python/blob/3cbb9e56be1f5b947d640f0b05710d7d032781be/examples/tool_permission_callback.py
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentation