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

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 a sandbox with isolated execution, it runs on your actual machine, kernel and CPU. Use at your own risk.

Installation

pip install malwi-box

Or with uv:

uv tool install malwi-box

Commands

Command Description
malwi-box run script.py Block operations not allowed in .malwi-box.toml
malwi-box run --review script.py Approve/deny each operation, save to config
malwi-box run --force script.py Log violations without blocking
malwi-box install package Install pip package with config restrictions
malwi-box config create Create default .malwi-box.toml

Quick Start

malwi-box config create
malwi-box run script.py

Examples

Audit a suspicious package

malwi-box install --review sketchy-package

Allow network access

malwi-box run examples/network_request.py

.malwi-box.toml:

allow_domains = ["httpbin.org"]

Allow file reads

malwi-box run examples/file_read.py

.malwi-box.toml:

allow_read = ["/etc/passwd"]

Allow shell commands

malwi-box run examples/system_command.py

.malwi-box.toml:

allow_shell_commands = ["/bin/ls *"]

Allow executables

malwi-box run examples/executable_control.py

.malwi-box.toml:

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

Review mode

malwi-box run --review examples/network_request.py
# 'y' to approve, 'n' to deny, 'i' to inspect call stack
# Approved operations saved to .malwi-box.toml

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
]

# 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

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)
  • Process execution (subprocess.Popen, os.exec*, os.system)
  • Library loading (ctypes.dlopen)

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
  • ctypes.dlopen is blocked by default to prevent native bypasses
  • Requires Python 3.10+

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.2.tar.gz (36.7 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.2-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (59.8 kB view details)

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

malwi_box-0.0.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (58.7 kB view details)

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

malwi_box-0.0.2-cp313-cp313-macosx_11_0_arm64.whl (34.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

malwi_box-0.0.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (57.1 kB view details)

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

malwi_box-0.0.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (56.2 kB view details)

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

malwi_box-0.0.2-cp312-cp312-macosx_11_0_arm64.whl (34.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

malwi_box-0.0.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (56.5 kB view details)

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

malwi_box-0.0.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (55.7 kB view details)

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

malwi_box-0.0.2-cp311-cp311-macosx_11_0_arm64.whl (34.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

malwi_box-0.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (56.2 kB view details)

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

malwi_box-0.0.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (55.4 kB view details)

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

malwi_box-0.0.2-cp310-cp310-macosx_11_0_arm64.whl (34.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: malwi_box-0.0.2.tar.gz
  • Upload date:
  • Size: 36.7 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.2.tar.gz
Algorithm Hash digest
SHA256 531e4edbec2eef3837a1bf01cc92afda09c334a4ead0ad639b428b3216039996
MD5 f89c9dbb01241696878c4d5886adcfab
BLAKE2b-256 328ff7914553ca371635a26f3bd8dfba0eebab7b714f2599c881d7b6801f3cf9

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2.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.2-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.2-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7829b8874db25aeb63bce2ae4a4dc940fa08d34162ece4afc81f5629881c3d00
MD5 dabee85c51e605d90ec97e5261b28440
BLAKE2b-256 e7b0772cb0b27a51a61c3d95eefb7da2f7cdbb20aab2d554b4348884205dc6aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 75cd8c1252c46b942591de330dc6427166ab8fbf6ae8bcb3a216beba67fe2fbb
MD5 b97834229604070a25a033383d4fdf06
BLAKE2b-256 2defed4d357276863deb8304e8997344b3bc126c20c4bf8d597cb1bec37496a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd37b1ed28b1b7479b03195a9044216a8e736cefc4a0729b55fae94c4a19341a
MD5 c7396eabade9fa131ebb98b4880e0b65
BLAKE2b-256 c5d26d976047a11cc014d08229a4a5bac34fcc2f6072fc10945071e948c1e0db

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 83f6883319e4c876735e733c151366e2836a1a3f962e83629e5ce8362bdb431f
MD5 97a98c7cc16f21ae1e37ca61bbabd582
BLAKE2b-256 aa39473bce169381d236127a0c0b66f39779ba2d0401d1628f44b14ba08c7a56

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dfb64e9fb4528f3a1a2bd69851752c9232c107b8361a99af0c3a534dd56a7296
MD5 076b081b1f9f042998e6428d480334a7
BLAKE2b-256 e55e904025a037c92fab2bd53ceecda835d6f34288b4f411848caf68510e0a06

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10b7f16c1971735fe56fed59afff5867834d32024c43d13a22220c64c2f5cd76
MD5 4516a7a6ceca3435ed601b2bc8a252bb
BLAKE2b-256 c49c547aca191fcb5cfaf39a2a5c7d4fe8251e1e97fbe6dbe5a6c44f9aa1bede

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2bda4d84a5db1d4a207016ffa13e82c8f40cdd2b09c30437e5039b62913c3f53
MD5 e6eeaf9a4481c47101ff1a73f92bce0d
BLAKE2b-256 717e8d3cbb332d5354de2f03a4b158c60890992b9187881804f46883b10c7af1

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 dcd8821ca23bfd6ef500cba29f73cb5bfa5e0546ec9cfef36d84300d896806da
MD5 26a4fc2c42fc7341d24babede340674d
BLAKE2b-256 4b77382d83b0787c5a31851176e5a0089230477d2aa93babaae90f7272af76fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 135a107ed8a51b10d529074910507b3ad6b03a5bddca3d7ea59f30a955abd880
MD5 002eef5c74fa83158b2b93e6c125b403
BLAKE2b-256 b30eb3421fed2bfefb7aeac111d50592ed0f161cae144af5043172f77a25dd05

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d55eccc8091f070ddb5b2fd2c14df3fcbcbf5cb2061f7c959daec37599d4dfa
MD5 594e3e9577ab0b71aa74af71aa649795
BLAKE2b-256 5d88446cb56048ed9d23926508d8222b444c09c48cd7160faf96cbc6a2227c20

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-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.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 96f2f5a6ea2e7cbf6be9afd454e8d73427fa549b28dae9bf0c4d33b3b2a6ea6d
MD5 b39a6edb5a178266091318aab2c8884f
BLAKE2b-256 3b99778944a33ad988ced2cb372dd23bb942a21c87aa64113f4595f95f062d45

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for malwi_box-0.0.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a572872769a05ef587abe3cdd2abf35befe061259aa5ae31c27fa212ac84fdc
MD5 7c0cd502771ba130572c6eff8de237aa
BLAKE2b-256 2d1690c371233675a6586e110c78b4c37f88d7f2202489baa11d0c3bfde83905

See more details on using hashes here.

Provenance

The following attestation bundles were made for malwi_box-0.0.2-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