Skip to main content

LogicVein Script Sandbox Utils

Convenience helpers for Python scripts that LogicVein Playbooks run in the Script Sandbox container. They wrap the sandbox's file-and-stdout contract: a Playbook hands your script its inputs in in.json, and your script returns results by printing JSON to stdout.

Installation

From PyPI:

pip install lvi-script-sandbox-utils

From TestPyPI (pre-release / testing):

pip install \
  --index-url https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ \
  lvi-script-sandbox-utils

The sandbox runs scripts in a container, so the package has to be available inside it. If your sandbox mounts a packages directory (for example ./packages:/packages), install into it:

pip install --target ./packages lvi-script-sandbox-utils

The library has no third-party dependencies (standard library only).

Upgrading from 0.1.x

0.1.x installed as logicvein.lvi_script_sandbox_utils. From 0.2.0 it is the top-level package lvi_script_sandbox_utils, so change

from logicvein import lvi_script_sandbox_utils as lvi

to import lvi_script_sandbox_utils as lvi. The logicvein package is left to lvi-api-client: when both shipped a logicvein/ directory, pip install --target skipped whichever was installed second (or, with --upgrade, deleted the first).

Usage

import lvi_script_sandbox_utils as lvi

device = lvi.get_device()
output = lvi.get_input("cli_output", default="")  # "" in the Playbook's first script node

lvi.flush_output(hostname=device.device_hostname, line_count=len(output.splitlines()))

Functions

Function Purpose
load_input(path=None, reload=False) The whole in.json as a dict, read once and cached. Treat it as read-only.
get_input(input_type, default=...) Read an input from in.json. "cli_output" returns the previous node's result value; "device" returns the raw device dict. A missing input returns default, or raises KeyError if none was given; any other input_type raises ValueError.
get_global(name, default=...) One Playbook global's value, e.g. get_global("hostname"). A missing global returns default, or raises KeyError naming the globals that are set.
get_globals() Every Playbook global as {name: value}.
get_metadata() Details of this run as an object: playbook, execution_id, executor, job_id, node, started_at, and so on.
get_device(blank_none=True) The Playbook's device as an object with a basic set of properties (see below).
get_full_device(blank_none=True) Like get_device(), with the additional properties included (uuid, lastBackup, severity, memoSummary, ...).
set_output(key, value) Record a global for the next flush_output().
flush_output(**kwargs) Print the set_output() values plus kwargs (which win on a clash) to stdout as Playbook global variables (output.globals), then clear the set_output() values. Device and metadata objects print as their fields.
flush_string_output(text) Print a string to stdout as base64-encoded raw output (output.raw).

On the device objects:

  • hostname and network are renamed to device_hostname and device_network, so they don't collide with other Playbook variables.
  • traits lists the device's capabilities from metaJson (ssh, snmp, ncm, ...); customFields is dropped, since it repeats custom1..custom5.
  • End-of-life/sale epochs (endOfLife, endOfSale, softwareEndOfLife, softwareEndOfSale) become YYYY-MM-DD dates, and lastBackup, lastChange, lastDiscovery, lastTelemetry become YYYY-MM-DDTHH:MM:SSZ timestamps, all in UTC. get_metadata().started_at is converted the same way.
  • None values become ""; pass blank_none=False to keep None.
  • A property LogicVein doesn't send is simply absent from the object.

vars(device) gives the properties as a dict.

Where the input comes from

in.json is read on first use, not at import, and only once; load_input() returns it as a dict (pass reload=True to read it again). The module attributes device and device_full are built the first time a script uses them. By default the file is in.json in the working directory, where the sandbox puts it; set LVI_SANDBOX_INPUT to read another file, e.g. a saved in.json while developing a script outside a Playbook:

LVI_SANDBOX_INPUT=./samples/in.json python my_script.py

Development and releases

See CONTRIBUTING.md for development setup and PUBLISHING.md for how releases are published.

Metadata

Release files for lvi-script-sandbox-utils 0.6.0

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

Source distribution (sdist)

Source distribution for lvi-script-sandbox-utils 0.6.0
File Size Uploaded Provenance Actions
lvi_script_sandbox_utils-0.6.0.tar.gz 13.4 kB Without provenance Details for lvi_script_sandbox_utils-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lvi-script-sandbox-utils 0.6.0
File Interpreter ABI Platform Actions
lvi_script_sandbox_utils-0.6.0-py3-none-any.whl Python 3 none any Details for lvi_script_sandbox_utils-0.6.0-py3-none-any.whl

Total release size: 25.0 kB

Release files / lvi_script_sandbox_utils-0.6.0.tar.gz

Download URL lvi_script_sandbox_utils-0.6.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
dc195d2ab23258c66572789a638dce802d0c1fd2756886ca229dd36142f638ee
BLAKE2b-256 checksum
How to use checksums
d90129e180bde63e6b9b2aea47e94aa065b91ac78626143b788ab732836b032f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Release files / lvi_script_sandbox_utils-0.6.0-py3-none-any.whl

Download URL lvi_script_sandbox_utils-0.6.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
617a1900df1da3c79b6bd9026ed50d49a312cc1de2c9e1ad12d8502d2aa30635
BLAKE2b-256 checksum
How to use checksums
8cee653d6113379990e28abe62993e72a962b6da74ba4bb5caa3689a97a70917
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.10

Security for lvi-script-sandbox-utils 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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