Budibase/budibase · error

Tool is not available in this security context

Error message

Tool is not available in this security context

What it means

AI tools executed under a runtime security context must declare an authorization configuration. When wrappedExecute detects a runtime (principal/executionContext present) but toolDef.authorization is missing, it refuses to run the tool to prevent unauthorized privileged execution. This guards against tools defined for anonymous/system contexts being invoked in an authenticated security context.

Source

Thrown at packages/server/src/ai/tools/index.ts:114

  })

const wrapTool = (
  toolDef: AiToolDefinition,
  runtime?: ToolAuthorizationRuntime,
  gate?: EscalationGateRuntime
): Tool => {
  const execute = toolDef.tool.execute
  if (!execute) {
    return toolDef.tool
  }

  const wrappedExecute: NonNullable<Tool["execute"]> = async (
    input,
    options
  ) => {
    if (runtime) {
      if (!toolDef.authorization) {
        throw new Error("Tool is not available in this security context")
      }
      await runtime.authorize({
        authorization: toolDef.authorization,
        input,
        executionContext: runtime.executionContext,
        principal: runtime.principal,
      })
    }
    if (gate) {
      return await gate.intercept(input, {
        toolCallId: options?.toolCallId ?? "",
        messages: options?.messages,
      })
    }
    try {
      const result = await execute(input, options)
      const failureMessage = getToolFailure(result)
      if (failureMessage) {

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Add an authorization definition to the tool definition (toolDef.authorization) appropriate to the security context
  2. If the tool is intentionally unauthenticated, execute it without a runtime context
  3. Audit the tool factory used to build the tool and ensure it always sets authorization

Example fix

// before
const tool: Tool = { name: "runQuery", execute }
// after
const tool: Tool = { name: "runQuery", authorization: { /* auth rules */ }, execute }
Defensive patterns

Strategy: validation

Validate before calling

if (runtime && !toolDef.authorization) throw new Error("Tool requires authorization config")

Type guard

const hasAuthorization = (t: Tool): t is Tool & { authorization: NonNullable<Tool["authorization"]> } => !!t.authorization

Try / catch

try { await wrappedExecute(input, options) } catch (e) { if (e.message.includes("security context")) { /* reconfigure tool auth or drop runtime */ } else throw e }

Prevention

When it happens

Trigger: Calling a tool via wrappedExecute when a runtime is set and toolDef.authorization is undefined — e.g. a tool created without the authorization field but executed by an authenticated agent.

Common situations: Developer adds a new tool definition and forgets to supply authorization; an existing tool designed for non-runtime contexts is reused inside an authenticated agent runtime; refactoring removed the authorization block.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/0c39edb807b0c21e. Report an issue: GitHub.