Skip to main content

BashVar Sentry

BashVar Sentry is a Python utility module that securely extracts Bash variable declarations from scripts by sourcing them in a sandboxed environment. It supports sandboxing via chroot, bwrap, or fakechroot to reduce risk from untrusted content.


📦 Installation

Install from PyPI:

pip install bashvar-sentry

🧰 Usage

As a Python module

from bashvar_sentry import source_and_get_vars

variables = source_and_get_vars(
    "example.sh",
    sandbox_method="auto",           # "auto", "chroot", "bwrap", "fakechroot", "empty"
    jail_dir="/",                    # Optional: target root dir for sandbox
    extra_env={"MYVAR": "from_python"},
    additional_args=["one", "two"]
)

print(variables)

📄 Bash Script Requirements

Your script must be syntactically valid (bash -n is run first).


Example Script: example.sh

#!/bin/bash

ARG1=$1
ARG2=$2
ENV_CAPTURED="$MYVAR"

declare -a FRUITS=("apple" "banana split")
declare -A CONFIG=([host]="localhost" [port]="8080")

Output

{
  "ARG1": "one",
  "ARG2": "two",
  "ENV_CAPTURED": "from_python",
  "FRUITS": ["apple", "banana split"],
  "CONFIG": {"host": "localhost", "port": "8080"}
}

🔐 Sandbox Methods

Method Isolation Root Required Notes
chroot Full Yes Needs /usr/sbin/chroot
bwrap Strong No Needs bwrap binary
fakechroot Simulated No Must have fakechroot
empty Minimal No Sets PATH=""
auto Best fit No Picks the first available

🚫 Caveats

  • Scripts are sourced, not executed. This means:
    • Side effects can persist in the current shell context.
    • Background jobs, subshells, etc., may behave differently.
  • Environment is isolated if you use sandboxing. If not, it's up to you.

✅ Testing

Run tests with:

python -m pytest

To test sandbox fallbacks, install:

  • /usr/sbin/chroot and run as root (for chroot) - This auto skips if not root
  • bwrap
  • fakechroot

📄 License

Apache-2.0

Metadata

Release files for bashvar-sentry 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bashvar-sentry 0.0.4
File Size Uploaded Provenance
bashvar_sentry-0.0.4.tar.gz 11.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bashvar-sentry 0.0.4
File Interpreter ABI Platform
bashvar_sentry-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / bashvar_sentry-0.0.4.tar.gz

Download URL bashvar_sentry-0.0.4.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
620ea0e26c994828edad31663eb5e29ea318bd379198c6e2bf9f15d2227d4537
BLAKE2b-256 checksum
How to use checksums
37926a01e467d253a60b74d1bffdaa7a02b91f23f08c4c0e5c400e2388c14081
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2025.

Transparency log

Release files / bashvar_sentry-0.0.4-py3-none-any.whl

Download URL bashvar_sentry-0.0.4-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
23b9203979f8d9438f404fd5caf0f892ad74cc58e7f1a769a30f78f5c294e8b9
BLAKE2b-256 checksum
How to use checksums
261a2d034d418c08be6d48ada9d00d662859810c45b2f83cd23afa2dab861f00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2025.

Transparency log

Security for bashvar-sentry 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bashvar_sentry-0.0.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 16, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page