agentskit.js
Security

Mandatory sandbox

Wrap tools with allow/deny lists and validators so agents cannot run unrestricted side effects.

Without explicit constraints, a tool-calling agent can invoke dangerous tools with arbitrary arguments. createMandatorySandbox (from @agentskit/sandbox) wraps each tool with a policy layer β€” calls that match the deny list, miss the allow list, or fail a validator are rejected before execution.

import { createMandatorySandbox, sandboxTool } from '@agentskit/sandbox'
import { filesystem, webSearch } from '@agentskit/tools'

const codeExecution = sandboxTool({ apiKey: process.env.E2B_API_KEY })

const mandatory = createMandatorySandbox({
  sandbox: codeExecution,
  policy: {
    allow: ['code_execution', 'web_search'],
    deny: ['filesystem'],
    requireSandbox: ['code_execution'],
    validators: {
      code_execution: (args) => {
        if (typeof args.code === 'string' && args.code.length > 10_000) {
          throw new Error('code too long')
        }
      },
    },
  },
})

const tools = [codeExecution, filesystem({ basePath: './workspace' }), webSearch()].map((t) =>
  mandatory.wrap(t),
)

#Modes

RuleEffect
allow: string[]only listed tool names pass
deny: string[]listed tool names rejected
requireSandbox: string[] | '*'matched tools route through sandbox.execute
validators: Record<name, fn>throw to reject with message

#requireSandbox semantics

When a tool is in requireSandbox, its original execute body is not run. Arguments are delegated to the shared sandbox tool's execute. This is a routing shim for code-execution style tools β€” it does not transparently wrap arbitrary tool implementations while still calling them.

Policy arrays/records are snapshotted at createMandatorySandbox time so later caller mutations cannot widen allow/deny/require decisions.

#Sandbox backends

  • E2B (optional peer @e2b/code-interpreter) β€” default cloud path
  • Web Worker (@agentskit/sandbox/web) β€” browser thread + DOM isolation only; not WebContainer
  • Custom SandboxBackend β€” Docker, Firecracker, etc.
  • Local runtimes β€” process / seatbelt / bwrap / docker for host-process isolation

See the sandbox deep dive.

Explore nearby

✎ Edit this page on GitHubΒ·Found a problem? Open an issue β†’Β·How to contribute β†’

On this page

Ask the docs
Ask anything about AgentsKit. Answers come from the docs corpus and cite their sources.