SecurityPolicy is passed to Sandbox.create() via the security parameter. It composes PII detection, injection defense, toxicity / code-security / invisible-text scanners, network policy, transformation rules, audit logging, and environment variable security into a single object.
SecurityPolicy
bool | InjectionDefenseConfig
default:"False"
Prompt injection defense. Pass
True to enable with defaults, or an
InjectionDefenseConfig for custom settings. See
InjectionDefenseConfig.list[TransformationRule]
default:"[]"
List of regex-based request/response body transformations. See
TransformationRule.
NetworkPolicy | None
default:"None"
Network allowlist/denylist policy. See NetworkPolicy.
bool | AuditConfig
default:"False"
Audit logging. Pass
True to enable with defaults, or an AuditConfig
for custom retention and body logging settings.ToxicityConfig | None
default:"None"
Toxicity scanner for outbound HTTP request bodies. See
ToxicityConfig.
CodeSecurityConfig | None
default:"None"
Code-security scanner for outbound HTTP request bodies. See
CodeSecurityConfig.
InvisibleTextConfig | None
default:"None"
Invisible-Unicode scanner for outbound HTTP request bodies. See
InvisibleTextConfig.
EnvSecurityConfig
default:"EnvSecurityConfig()"
Environment variable masking in audit logs. See
EnvSecurityConfig.
CustomPolicyConfig | None
default:"None"
Attach OPA/Rego policy — a built-in governance pack via
policy_ref, or your
own rules via inline_rego/inline_modules. See
CustomPolicyConfig.ContentGateConfig | None
default:"None"
Run the
content.scan OPA gate (e.g. an LLM model allowlist / cross-signal
rules) on the listed domains. See ContentGateConfig.Properties
Methods
PIIConfig
Configure detection and handling of personally identifiable information in outbound HTTP traffic.bool
default:"False"
Whether PII scanning is active.
list[str]
default:"all types"
PII types to scan for. Defaults to all
PIIType values. Valid values are
the string values of PIIType.str
default:"'redact'"
Action to take when PII is detected. One of
'redact', 'block',
'log_only'.bool
default:"True"
When
True, the security proxy replaces redaction tokens in API responses
with the original values so the agent sees real data in replies.list[str] | None
default:"None"
Limit PII scanning to requests targeting these domains.
None means scan
all domains.PIIType enum
RedactionAction enum
InjectionDefenseConfig
Detect and block prompt injection attempts in outbound HTTP request bodies.bool
default:"False"
Whether injection defense is active.
str
default:"'log_only'"
Action when injection is detected. One of
'block' (HTTP 403) or
'log_only' (forward unchanged, record detection in the audit log).str
default:"'medium'"
Preset sensitivity tier. One of
'low', 'medium', 'high'. Adjusts the
scanner’s detection aggressiveness independently of threshold.float
default:"0.8"
Confidence threshold between
0.0 and 1.0. Requests with a score above
this value trigger the configured action. Lower values increase sensitivity.list[str] | None
default:"None"
Limit injection scanning to these domains.
None means scan all.InjectionAction enum
InjectionSensitivity enum
ToxicityConfig
Scan outbound HTTP request bodies for toxic content (harassment, hate speech, etc.).bool
default:"False"
Whether toxicity scanning is active.
float
default:"0.9"
Confidence threshold between
0.0 and 1.0. Requests scoring above this
value trigger the configured action.str
default:"'block'"
Action when toxic content is detected. One of
'block' (HTTP 403) or
'log_only'.CodeSecurityConfig
Detect suspicious or unsafe code in outbound HTTP request bodies.bool
default:"False"
Whether code-security scanning is active.
float
default:"0.6"
Confidence threshold between
0.0 and 1.0.str
default:"'log_only'"
Action when suspicious code is detected. One of
'block' (HTTP 403) or
'log_only'.list[str] | None
default:"None"
Languages to exclude from scanning. Useful when content is intentionally
code but already in a trusted context.
InvisibleTextConfig
Detect invisible or control Unicode characters (often used to smuggle prompt instructions past the model) in outbound HTTP request bodies.bool
default:"False"
Whether invisible-text scanning is active.
str
default:"'strip'"
Action when invisible characters are detected. One of
'block' (HTTP 403),
'strip' (remove the characters and forward), or 'log_only'.CustomPolicyConfig
Attach OPA/Rego policy — a built-in governance pack viapolicy_ref, or your
own rules via inline_rego / inline_modules. Custom rules are evaluated at
the enforcement layer alongside the platform defaults and can only tighten
policy, never relax it.
bool
default:"False"
Whether custom policy evaluation is active for the sandbox.
str | None
default:"None"
A single Rego module string appended to the platform defaults. Use this for
a single-package policy.
list[str] | None
default:"None"
A list of independent Rego module strings, each its own
package. Use this
when your policy spans multiple packages; for a single package use
inline_rego instead.str | None
default:"None"
Reference a published or built-in policy bundle by
name@version (e.g.
owasp-llm-top10@v1), sha256:<hex>, or blob:<key>. See
Governance Packs for the catalog.bool
default:"False"
Fail-closed behavior: when
True, an evaluator error or unreachable engine
denies the action. Fail-closed is safer for hard security gates; fail-open
(False) is acceptable for advisory-only scanners.ContentGateConfig
Run thecontent.scan OPA gate (e.g. an LLM model allowlist / cross-signal
rules) on the listed domains. Opts a sandbox into content-gate enforcement
without requiring an ML scanner to be enabled.
bool
default:"False"
Whether the content gate is active.
list[str] | None
default:"None"
Opt-in list of destination hosts to intercept. Empty or
None means no
hosts are intercepted.NetworkPolicy
Network allowlist and denylist for outbound traffic from the sandbox. Set this onSecurityPolicy.network to apply it alongside other security controls.
list[str]
default:"[]"
Destinations to allow. Accepts IP addresses, CIDR blocks (e.g.
"10.0.0.0/8"), and domain names with optional wildcard prefix (e.g.
"*.github.com").list[str]
default:"[]"
Destinations to deny. Accepts IP addresses and CIDR blocks only (domains
not accepted in deny rules).
bool
default:"True"
Whether to allow all public traffic by default. Set to
False when using
allow_out to build an allowlist.str | None
default:"None"
Replace the
Host header in all outbound requests with this value. Used
for routing through a reverse proxy.ALL_TRAFFIC constant
deny_out=[ALL_TRAFFIC] to block all outbound traffic.
SandboxNetworkOpts
SandboxNetworkOpts is the lower-level equivalent used directly in Sandbox.create(network=...). It has the same fields as NetworkPolicy using snake_case attribute names.
TransformationRule
Regex-based text transformation applied to outbound request bodies, inbound response bodies, or both.str
required
Python-compatible regular expression. Must be a valid regex pattern.
str
required
Replacement string. Supports Python
re.sub back-references (e.g. \1).str
default:"'outbound'"
Direction to apply the rule. One of
'outbound', 'inbound', 'both'.TransformDirection enum
Methods
AuditConfig
Toggle whether lifecycle and security events for the sandbox are shipped to Declaw’s audit log.bool
default:"True"
When
True (the default), the orchestrator records the sandbox’s
lifecycle events (create, kill, pause, resume, snapshot) and security
decisions (egress allow/block) to the audit log. Set to False to
suppress all audit events for the sandbox.AuditEntry
EnvSecurityConfig
Control how environment variable values are masked in audit logs.list[str]
Glob patterns matched against uppercase environment variable names. Variables
matching any pattern are masked as
*** in audit logs.bool
default:"True"
Automatically redact matching variable values in all audit log entries.