Skip to main content

Run commands in an isolated environment, e.g. a Docker container

Project description

run-isolated - run commands in an isolated environment, e.g. a Docker container

[Home | Download | sourcehut | PyPI | ReadTheDocs]

Overview

The run-isolated library allows programs to invoke some actions in an isolated, clean environment, with read-only or read/write access to existing filesystem directories.

Currently the only isolated environment supported is a Docker container.

Examples

Start a container with commands run as a non-root account by default, run a command as root, grab another command's output:

PATH_SRC: Final = pathlib.Path("/opt/src")
PATH_WORK: Final = pathlib.Path("/opt/work")

with rdocker.Container.start_container(
    run_isolated.Config(
        log=util.build_logger(name="ri-example", verbose=True),
        uid=1000,
        gid=1000,
    ),
    "debian:trixie",
    volumes=[
        rdocker.ContainerVolume(
            external=pathlib.Path.cwd(),
            internal=PATH_SRC,
            readonly=True,
        ),
        rdocker.ContainerVolume(
            external=pathlib.Path.cwd() / "work",
            internal=PATH_WORK,
            readonly=False,
        ),
    ],
) as cont:
    cont.run_command(["apt-get", "update"], ugid="0:0", cwd=pathlib.Path("/"))

    lines = cont.run_command_output(
        ["find", ".", "-mindepth", "1", "-maxdepth", "1", "-type", "f"],
    ).splitlines()

    cont.run_command(
        [
            "env",
            f"PYTHONPATH={PATH_SRC / 'src'}",
            "python3",
            "-B",
            "-u",
            "-m",
            "ri_example.worker",
            "-o",
            PATH_WORK,
        ],
    )

Contact

The run-isolated library was written by Peter Pentchev. It is developed in a sourcehut repository. This documentation is hosted at Ringlet with a copy at ReadTheDocs.

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

run_isolated-0.1.2.tar.gz (499.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

run_isolated-0.1.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file run_isolated-0.1.2.tar.gz.

File metadata

  • Download URL: run_isolated-0.1.2.tar.gz
  • Upload date:
  • Size: 499.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for run_isolated-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e4ecaadd7d1bf2a7516e6af80c1705f2736c3c780b34ecdcbdc679657125f10b
MD5 9abb210286aff8841beb641fbe6df085
BLAKE2b-256 99539c4271e43fab0af935f91a42b0159bdebf0456d2bf74f9da52316492ddd7

See more details on using hashes here.

File details

Details for the file run_isolated-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: run_isolated-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for run_isolated-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 763d9239d38f5e1a354980794124faed857ee3f1507c6fee66bebadc72a3c24b
MD5 6e09bcbe0bd9a10256f17a6b2e35dab3
BLAKE2b-256 a21101ddd251fdf0ccf647460c61def44ab919e4b4ac35fa91b764bb4b1fedb3

See more details on using hashes here.

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