Skip to main content

Intercept, audit, and block critical Python operations at runtime

Project description

malwi-box logo

malwi-box

Intercept, audit, and block critical Python operations at runtime.

Shipped without any dependencies, except pip

malwi-box demo

Use Cases

  • 🔬 Malware analysis - Safely detonate suspicious Python code and observe its behavior
  • 📦 Dependency auditing - Discover what file, network, and process access a package actually needs
  • 🔒 Runtime protection - Enforce allowlists to block unauthorized operations in production

Warning: This tool is not executed in isolation or virtualization, it runs on your actual machine, kernel and CPU. Use it at your own risk. Still it allows to reduce the blast radius of typical Python malware.

Installation

pip install malwi-box

Or with uv:

uv tool install malwi-box

Quick Start

$ malwi-box eval "open('/etc/passwd').read()"

[malwi-box] Blocked: Read file: /etc/passwd

Commands

run

Run a Python script or module with sandboxing.

malwi-box run script.py [args...]
malwi-box run --force script.py     # log violations without blocking
malwi-box run --review script.py    # approve/deny each operation

eval

Execute a Python code string with sandboxing.

malwi-box eval "print('hello')"
malwi-box eval --force "import os; os.system('id')"
malwi-box eval --review "open('/etc/passwd').read()"

install

Install pip packages with sandboxing. Most malware packages perform malicious activities at install-time.

malwi-box install package
malwi-box install package --version 1.2.3
malwi-box install -r requirements.txt
malwi-box install --review package  # approve/deny each operation

config

Manage configuration.

malwi-box config create             # creates .malwi-box.toml
malwi-box config create --path FILE

Configuration Reference

Config file: .malwi-box.toml

# File access permissions
allow_read = [
  "$PWD",                     # working directory
  "$PYTHON_STDLIB",           # Python standard library
  "$PYTHON_SITE_PACKAGES",    # installed packages
  "$HOME/.config/myapp",      # specific config directory
  "/etc/hosts",               # specific file
]

allow_create = [
  "$PWD",                     # allow creating files in workdir
  "$TMPDIR",                  # allow temp files
]

allow_modify = [
  "$PWD/data",                # only modify files in data/
  { path = "/etc/myapp.conf", hash = "sha256:abc123..." },
]

allow_delete = []             # no deletions allowed

# Network permissions
allow_domains = [
  "pypi.org",                 # allow any port
  "files.pythonhosted.org",
  "api.example.com:443",      # restrict to specific port
]

allow_ips = [
  "10.0.0.0/8",               # CIDR notation
  "192.168.1.100:8080",       # specific IP:port
  "[::1]:443",                # IPv6 with port
]

# HTTP URL path restrictions (optional, empty = domain-only mode)
allow_http_urls = [
  "api.example.com/v1/*",         # glob pattern for paths
  "cdn.example.com/assets/*",
  "https://secure.example.com/*", # explicit scheme
]

# HTTP methods allowed (optional, empty = all methods)
allow_http_methods = ["GET", "POST", "HEAD"]

# Raw socket access (default: false, blocks SOCK_RAW creation)
allow_raw_sockets = false

# Process execution
allow_executables = [
  "/usr/bin/git",             # allow by path
  "$PWD/.venv/bin/*",         # glob pattern
  { path = "/usr/bin/curl", hash = "sha256:abc123..." },
]

allow_shell_commands = [
  "/usr/bin/git *",           # glob pattern matching
  "/usr/bin/curl *",
]

# Environment variables
allow_env_var_reads = []      # restrict env access
allow_env_var_writes = ["PATH", "PYTHONPATH"]

Path Variables

Variable Description
$PWD Working directory
$HOME User home directory
$TMPDIR System temp directory (macOS: /var/folders/.../T, Linux: /tmp)
$CACHE_HOME User cache directory (macOS: ~/Library/Caches, Linux: ~/.cache)
$PIP_CACHE pip cache directory
$VENV Active virtualenv root (if $VIRTUAL_ENV is set)
$PYTHON_STDLIB Python standard library
$PYTHON_SITE_PACKAGES Installed packages (purelib)
$PYTHON_PLATLIB Platform-specific packages
$PYTHON_PREFIX Python installation prefix
$ENV{VAR} Any environment variable

Sensitive Paths (Always Blocked)

The following paths are automatically blocked even if they match an allow rule:

  • SSH keys and GPG (~/.ssh, ~/.gnupg)
  • Cloud credentials (~/.aws, ~/.azure, ~/.config/gcloud, ~/.kube)
  • Browser data (Chrome, Firefox, Safari, Edge)
  • Password managers (1Password, Bitwarden, KeePassXC, keychains)
  • Development secrets (~/.npmrc, ~/.pypirc, ~/.netrc, ~/.git-credentials)
  • System secrets (/etc/shadow, /etc/sudoers, /etc/ssh/*_key)

Network Behavior

  • Domains in allow_domains automatically permit their resolved IPs
  • Direct IP access requires explicit allow_ips entries
  • CIDR notation supported for IP ranges
  • Port restrictions supported for both domains and IPs

HTTP URL Path Allowlisting

  • If allow_http_urls is empty, only domain-level checks apply (default behavior)
  • If allow_http_urls is configured, requests must match both domain AND URL pattern
  • Scheme (http://, https://) is optional in patterns - omit to match both
  • Glob patterns supported for paths: api.example.com/v1/*
  • Subdomain matching: example.com/api/* matches api.example.com/api/*

HTTP Method Restrictions

  • If allow_http_methods is empty, all HTTP methods are allowed
  • If configured, only listed methods are permitted (e.g., ["GET", "HEAD"])

HTTP Library Coverage

HTTP request interception covers:

  • urllib.request (stdlib)
  • http.client (stdlib)
  • urllib3
  • requests
  • httpx
  • aiohttp

Bypass note: Raw socket HTTP requests bypass library hooks but are blocked by default (allow_raw_sockets = false). The socket.connect event still captures all connections at the network level.

Hash Verification

Executables and files can include SHA256 hashes:

allow_executables = [
  { path = "/usr/bin/git", hash = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
]

How It Works

Uses Python's PEP 578 audit hooks via a C++ extension to intercept:

  • File operations (open)
  • Network requests (socket.connect, socket.getaddrinfo)
  • HTTP requests (urllib.Request + profile hooks for requests, httpx, urllib3, aiohttp, http.client)
  • Process execution (subprocess.Popen, os.exec*, os.system)
  • Library loading (ctypes.dlopen)
  • Raw socket creation (socket.__new__ with SOCK_RAW)

Protections against bypass:

  • Blocks sys.addaudithook to prevent registering competing hooks
  • Blocks sys.settrace and sys.setprofile to prevent debugger-based evasion
  • Blocks ctypes.dlopen by default to prevent loading native code that bypasses hooks

Blocked operations terminate immediately with exit code 78.

Limitations

  • Audit hooks cannot be bypassed from Python, but native code can
  • Here it is important to review which executables are allow-listed

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

malwi_box-0.0.3.tar.gz (44.4 kB view details)

Uploaded Source

Built Distributions

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

malwi_box-0.0.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (74.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

malwi_box-0.0.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (72.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

malwi_box-0.0.3-cp313-cp313-macosx_11_0_arm64.whl (40.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

malwi_box-0.0.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (71.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

malwi_box-0.0.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (70.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

malwi_box-0.0.3-cp312-cp312-macosx_11_0_arm64.whl (40.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

malwi_box-0.0.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (72.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

malwi_box-0.0.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (71.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

malwi_box-0.0.3-cp311-cp311-macosx_11_0_arm64.whl (40.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

malwi_box-0.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (72.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

malwi_box-0.0.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (71.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

malwi_box-0.0.3-cp310-cp310-macosx_11_0_arm64.whl (40.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file malwi_box-0.0.3.tar.gz.

File metadata

  • Download URL: malwi_box-0.0.3.tar.gz
  • Upload date:
  • Size: 44.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for malwi_box-0.0.3.tar.gz
Algorithm Hash digest
SHA256 8c37690c945c8092b10744bd2b024024a13a545d61752060769575a76d475123
MD5 1e9321d99b5767ac938eb123e0d53861
BLAKE2b-256 eb5ee17d46c1a0390d6ee933a804a07652324ca6df25d0500b8d064a05f995b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3.tar.gz:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d23cab81f4f8a25028a2063be540d7fcf99b07f0eb3b48b42f5fcc1a120d5bc
MD5 d6f2ea229a92381a3e130f861dc0ee57
BLAKE2b-256 7941b579e906b01d2f15c96b643cffd0b0a03a0287ebe1b2dcb17562a64f0de7

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0f22f4ae3dcbb713e0216c0c595598ff49d91f19d7ec264f9a067b2626cf969e
MD5 19ead3de207bfe4439dac60b7ce48564
BLAKE2b-256 3a595ad759355893f8244536ed99f226b66cfd581d1ccb397ecb4f2ccf816640

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3824732072547d227f3efe795fd4f207597af372bd4a2a2c4691672f75fb51c4
MD5 ed02cd0e658d46113e024012f7c724fb
BLAKE2b-256 7ebd62dd5a33c27c9654eded4e73e5c2a981051f86122a026c1fa45b4603b7a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a4b2e3e2cae670dfe0ed03f5a08f363e6ad9852a6a09688a2f489417d6ad9df
MD5 6d7701f667701ffedb39e19ae924108d
BLAKE2b-256 a4e2fddac936a62d2cd524f97dcd99e0e7b6e003afaf44b429e174c474e03617

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fbcb78bbd6d70572384a5334a600822a773154924cc868c47a8a456502d414e6
MD5 270fa27f082b6641b09b5136c65c8d55
BLAKE2b-256 bd9b9efb1ac5223f7368da274c8aafeb866c83d9fbd5ca2b2410c8b92a4593b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7beec7c590d8509c81e6e29b529164163e15f76ca7ef344a81bbe0ab772c48e4
MD5 015e54068e6aa98fcf751978382b611f
BLAKE2b-256 b260eef1cb7a0e63f1ca551520d0d6136cd3945b819e6503cae7e92b57d5e3c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7df137d9e3237eff672343da6456c63900a160bc56ef1e7177ec60ba28fc6e6b
MD5 43facc6f637e28c9289a13b6986e3ede
BLAKE2b-256 53167cda6148071e257c105010b3ea2ffbf12f23e8c7060a7d0409a35d4cd9a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1db28f778a4512470b8648a35aff1d2dbc44cd8c168c627012c8e14c1f2d4d56
MD5 dca4408437b43a2bd8d75af84bee08fe
BLAKE2b-256 25d519a3c2d1b8d21035193c6640687f0564ad039b2cd99ee4e462037a676c3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 31ace59ad70fb36af390e62eeb99a010912d75a9025345bbc218873c8c46a131
MD5 e2cbd3c83e75fceece6fefc2ea77a638
BLAKE2b-256 f46f1111504e53f8e0220708cc56fd3fdde536a68a1f729d3b65a2b2fb01cabb

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 68f14d37081f20419d7dba5db088ff129a360272bb98b2f59d418b7f601307e5
MD5 c908bbccd2cd5e4de4c4e4087b4400c0
BLAKE2b-256 6b1c7c54854e3202233604a138cec632dd468297753be3bd0f60f48e48b4797c

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 56e4382afccb168fd2938763cde36a1f6ab995a85462ff9a83de7f50e98ee023
MD5 ac05d87e98b566c6c1ec61518d40bf03
BLAKE2b-256 680fa787f94dae99eb2fd26e66f6ae8ad0e5eec67a6804b220b7a4ce23d5a6db

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file malwi_box-0.0.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abc1f1ba8bc40e949c2bd5b41f3d4a9e6ca68a2546c2651ff3529692436ca388
MD5 648f4cba02170c1aaceb6f53e43d043c
BLAKE2b-256 61ab6621482b3c8c575c8ccea8e2de5827cd463215e34d725cae4b720a89af7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.3-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on canvascomputing/malwi-box

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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