Skip to content

Sandbox Config

SandboxConfig defines the security sandbox applied to tool execution. When a sandbox is active, the agent's tools are constrained in what they can read, write, and connect to — protecting the host system from unintended or malicious tool behaviour.

The sandbox is applied per-agent and enforces restrictions at the OS level where supported.


Static Presets

Four preset configs are provided for common scenarios. Prefer a preset as a starting point and adjust from there.

csharp
// Default — reasonable write allow-list, SSH/AWS credential deny-list
var sandbox = SandboxConfig.CreateDefault();

// Permissive — minimal restrictions, suitable for trusted tool environments
var sandbox = SandboxConfig.CreatePermissive();

// MCP-specific defaults
var sandbox = SandboxConfig.CreateForMCP();

// Tightened defaults with stricter rules
var sandbox = SandboxConfig.CreateEnhanced();

// Enhanced + MCP
var sandbox = SandboxConfig.CreateEnhancedForMCP();

Properties

File System Access

PropertyTypeDefaultDescription
AllowWritestring[][".", "/tmp"]Paths where tools are allowed to write
DenyReadstring[]["~/.ssh", "~/.aws", "~/.gnupg"]Paths that tools are never allowed to read
DenyWritestring[][]Paths that tools are never allowed to write

Network Access

PropertyTypeDefaultDescription
AllowedDomainsstring[]?[]Domains tools are permitted to connect to. Empty = all allowed
DeniedDomainsstring[][]Domains explicitly blocked
ExternalHttpProxyPortint?nullRoute HTTP through an external proxy on this port
ExternalSocksProxyPortint?nullRoute traffic through a SOCKS proxy on this port

Unix / System Access

PropertyTypeDefaultDescription
AllowAllUnixSocketsboolfalseAllow tools to connect to any Unix domain socket
AllowUnixSocketsstring[]?nullSpecific Unix socket paths to allow
AllowPtyboolfalseAllow tools to allocate a pseudoterminal
AllowLocalBindingboolfalseAllow tools to bind to local ports
AllowGitConfigboolfalseAllow reading Git config files
AllowedEnvironmentVariablesstring[]["PATH", "HOME", "TERM", "LANG"]Environment variables tools can access

Scoping

PropertyTypeDefaultDescription
SandboxableFunctionsstring[][]Function names the sandbox applies to. Empty = all functions
ExcludedFunctionsstring[][]Function names explicitly excluded from sandboxing
MandatoryDenySearchDepthint3Directory recursion depth when evaluating deny-list paths

Behavior on Failure / Violation

PropertyTypeDefaultDescription
OnInitializationFailureSandboxFailureBehaviorBlockWhat to do if the sandbox cannot be initialized
OnViolationSandboxViolationBehaviorEmitEventWhat to do when a tool attempts a restricted operation
EnableWeakerNestedSandboxboolfalseAllow a less strict sandbox inside an already-sandboxed process
EnableViolationMonitoringboolfalseContinuously monitor for violations rather than only on access
IgnoreViolationPatternsstring[]?nullGlob patterns for violations to silently ignore

Enums

SandboxFailureBehavior

ValueDescription
BlockRefuse to start the agent if the sandbox cannot be established
WarnLog a warning and continue without sandboxing
IgnoreSilently continue without sandboxing

SandboxViolationBehavior

ValueDescription
EmitEventEmit a violation event but allow the operation to proceed
BlockAndEmitBlock the operation and emit a violation event
IgnoreAllow the operation silently

Examples

Restrict to specific domains

csharp
var sandbox = SandboxConfig.CreateDefault();
sandbox.AllowedDomains = ["api.myservice.com", "cdn.myservice.com"];
sandbox.DeniedDomains = ["example-malicious.com"];

Block violations hard

csharp
var sandbox = SandboxConfig.CreateEnhanced();
sandbox.OnViolation = SandboxViolationBehavior.BlockAndEmit;

Scope to specific tools only

csharp
var sandbox = SandboxConfig.CreateDefault();
sandbox.SandboxableFunctions = ["ExecuteShellCommand", "WriteFile"];
sandbox.ExcludedFunctions = ["ReadPublicFile"];

Validation

Call sandbox.Validate() after configuring to catch configuration errors before building the agent:

csharp
var sandbox = SandboxConfig.CreateDefault();
sandbox.AllowWrite = ["/safe/output"];
sandbox.Validate();   // throws ArgumentException if config is inconsistent

See Also

Released under the MIT License.