Skip to main content

Inspect AI extension for policy-enforced sandbox environments

Project description

Inspect Policy Sandbox Extension

A standalone extension for Inspect AI that provides a policy-enforced sandbox environment.

Overview

The inspect-policy-sandbox extension allows you to wrap any existing Inspect sandbox environment (e.g., local, docker) and enforce strict policies on:

  • Execution: Allow or deny specific commands.
  • Read Access: Allow or deny reading specific files.
  • Write Access: Allow or deny writing to specific files.

When a policy violation occurs, the extension:

  1. Raises a SandboxPolicyViolationError (subclass of PermissionError).
  2. Logs a SandboxEvent with result=1 and reason="policy".

Installation

This extension is designed to be installed in a Python virtual environment where inspect-ai is also installed.

# Install from source
pip install -e .

Usage

Enable the extension in your Inspect task by specifying the sandbox type as policy-sandbox.

You can configure the policy via task metadata or configuration.

Example Task

from inspect_ai import Task, eval
from inspect_ai.dataset import FieldSpec
from inspect_ai.solver import system_message

# Define task using the policy sandbox
task = Task(
    dataset=[], 
    solver=[system_message("Run a command")],
    sandbox="policy-sandbox",
    sandbox_config={
        # Configuration for the inner sandbox (if needed)
    }
)

# Pass policy configuration in metadata at runtime or task definition
# Note: Currently policy configuration is extracted from sample metadata or task metadata 
# depending on how you pass it. The extension looks for a 'policy' dictionary in metadata.

Policy Configuration

The policy is defined by a dictionary with the following keys:

  • deny_exec: List of glob patterns for commands to deny (e.g., ["rm", "sudo"]).
  • allow_exec: List of glob patterns for commands to allow (whitelist).
  • deny_read: List of glob patterns for files to deny reading.
  • allow_read: List of glob patterns for files to allow reading.
  • deny_write: List of glob patterns for files to deny writing.
  • allow_write: List of glob patterns for files to allow writing.

Example Metadata:

{
  "policy": {
    "deny_exec": ["rm", "curl"],
    "deny_write": ["/etc/*"]
  },
  "inner_sandbox": "local"
}

Development

  1. Create a virtual environment:
    python3 -m venv .venv
    source .venv/bin/activate
    
  2. Install dependencies:
    pip install -e .[dev]
    
  3. Run tests:
    pytest tests/
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

inspect_policy_sandbox-0.1.2.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inspect_policy_sandbox-0.1.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file inspect_policy_sandbox-0.1.2.tar.gz.

File metadata

  • Download URL: inspect_policy_sandbox-0.1.2.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for inspect_policy_sandbox-0.1.2.tar.gz
Algorithm Hash digest
SHA256 48c160031779f2e05beb42941dc4902b76439a85c00baff167669c7f26784e20
MD5 0b1a63daa57cf80852f0bfc51c7bb18c
BLAKE2b-256 7b43b2d073cddcf8b71493365c4f29bebde5ad7009c5a608038d0cf1fe74a2a5

See more details on using hashes here.

File details

Details for the file inspect_policy_sandbox-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for inspect_policy_sandbox-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 df69204d3ac4bd550b37ee2fad6b5a9ae22001b77f6d334cfdca15351a858716
MD5 ec7f4bad2a45479005daf4946ea9d7aa
BLAKE2b-256 d214262a108a31ab7b50b6ac9229ee4435293b803c94f2e7404a3c22c3af25f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page