agentskit.js
Security

Mandatory sandbox

Wrap any tool with allow/deny lists and validators so agents can't execute commands you haven't explicitly permitted.

Without explicit constraints, a tool-calling agent can run arbitrary shell commands. createMandatorySandbox wraps any tool with a policy layer β€” calls that don't match the allow list, match the deny list, or fail a validator are rejected before execution.

import { createMandatorySandbox } from '@agentskit/tools'
import { shell } from '@agentskit/tools'

const guarded = createMandatorySandbox(shell(), {
  allow: ['ls', 'cat', 'grep'],
  deny: ['rm', 'sudo', 'curl', 'wget'],
  requireSandbox: true,
  validators: [
    (args) => args.cmd.length < 256 || 'command too long',
  ],
})

#Modes

RuleEffect
allow: string[]only listed cmds pass
deny: string[]listed cmds rejected
requireSandbox: trueexecute via @agentskit/sandbox
validators: Fn[]return string to reject with message

#Sandbox backends

E2B (default) Β· WebContainer Β· Deno worker β€” see sandbox package.

Explore nearby

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

On this page