A robust Python module to safely source a bash script in a sandboxed environment and collect its variables.
Project description
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/chrootand run as root (for chroot) - This auto skips if not rootbwrapfakechroot
📄 License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bashvar_sentry-0.0.4.tar.gz.
File metadata
- Download URL: bashvar_sentry-0.0.4.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
620ea0e26c994828edad31663eb5e29ea318bd379198c6e2bf9f15d2227d4537
|
|
| MD5 |
ba138f627f82c98c96a8c2b59ba38c82
|
|
| BLAKE2b-256 |
37926a01e467d253a60b74d1bffdaa7a02b91f23f08c4c0e5c400e2388c14081
|
Provenance
The following attestation bundles were made for bashvar_sentry-0.0.4.tar.gz:
Publisher:
pypi-publish.yml on envolution/bashvar-sentry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bashvar_sentry-0.0.4.tar.gz -
Subject digest:
620ea0e26c994828edad31663eb5e29ea318bd379198c6e2bf9f15d2227d4537 - Sigstore transparency entry: 238908288
- Sigstore integration time:
-
Permalink:
envolution/bashvar-sentry@48dda2344c7d0d471e509a9a261a356bd57e6b84 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@48dda2344c7d0d471e509a9a261a356bd57e6b84 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bashvar_sentry-0.0.4-py3-none-any.whl.
File metadata
- Download URL: bashvar_sentry-0.0.4-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23b9203979f8d9438f404fd5caf0f892ad74cc58e7f1a769a30f78f5c294e8b9
|
|
| MD5 |
2c177d3f17754af3babe58d3431aa1db
|
|
| BLAKE2b-256 |
261a2d034d418c08be6d48ada9d00d662859810c45b2f83cd23afa2dab861f00
|
Provenance
The following attestation bundles were made for bashvar_sentry-0.0.4-py3-none-any.whl:
Publisher:
pypi-publish.yml on envolution/bashvar-sentry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bashvar_sentry-0.0.4-py3-none-any.whl -
Subject digest:
23b9203979f8d9438f404fd5caf0f892ad74cc58e7f1a769a30f78f5c294e8b9 - Sigstore transparency entry: 238908291
- Sigstore integration time:
-
Permalink:
envolution/bashvar-sentry@48dda2344c7d0d471e509a9a261a356bd57e6b84 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/envolution
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@48dda2344c7d0d471e509a9a261a356bd57e6b84 -
Trigger Event:
push
-
Statement type: