You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

bashvar-sentry

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bashvar-sentry

A robust Python module to safely source a bash script in a sandboxed environment and collect its variables.

0.0.4
pipPyPI
Maintainers
1

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

MethodIsolationRoot RequiredNotes
chrootFullYesNeeds /usr/sbin/chroot
bwrapStrongNoNeeds bwrap binary
fakechrootSimulatedNoMust have fakechroot
emptyMinimalNoSets PATH=""
autoBest fitNoPicks 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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts