Skip to main content

ContainerBox

Minimal docker based sandbox for running generated code and bash commands with uploading files, custom images and donwloading the results.

Usage

Use the context manager when the sandbox belongs to one block of work:

from containerbox import SandboxSession

with SandboxSession() as session:
    result = session.exec("echo hi")
    print(result.stdout)

Use manual lifecycle when you need to pass the same sandbox across functions or modules:

from containerbox import SandboxSession

session = SandboxSession("python:3.13-slim")
session.open()

try:
    result = session.run_code("print('hi')", timeout=5)
    print(result.stdout)
finally:
    session.close()

When using manual lifecycle, always call close(). The context manager does this for you; manual mode makes cleanup your responsibility.

API

with SandboxSession(
    image="ubuntu:24.04",
    runtime="docker",
    session_timeout=300,
    memory="256m",
    cpus=1.0,
    network=False,
) as session:
    result = session.exec("echo ready", timeout=10)

For Python code, use a Python image:

with SandboxSession("python:3.13-slim") as session:
    result = session.run_code("print('hi')", timeout=5)

SandboxResult contains:

  • stdout
  • stderr
  • exit_code
  • timed_out
  • duration_ms

Files

with SandboxSession("python:3.13-slim") as session:
    session.upload("local_data.csv")
    result = session.run_code("print(open('local_data.csv').read())")
    session.download("main.py", "downloaded_main.py")

Custom Image

Create a Dockerfile in your own project:

FROM node:22-slim

WORKDIR /workspace

RUN npm init -y && npm install slugify

ENV NODE_PATH=/workspace/node_modules

Build it:

docker build -t my-node-sandbox:latest .

Use that image with ContainerBox:

from containerbox import SandboxSession

code = """
const slugify = require("slugify");
console.log(slugify("Hello from Custom Node Image!", { lower: true }));
"""

with SandboxSession("my-node-sandbox:latest") as session:
    result = session.run_code(code, filename="main.js", command=["node", "main.js"])
    print(result.stdout)

Metadata

Release files for containerbox 0.1.2

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

Source distribution (sdist)

Source distribution for containerbox 0.1.2
File Size Uploaded Provenance
containerbox-0.1.2.tar.gz 5.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for containerbox 0.1.2
File Interpreter ABI Platform
containerbox-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / containerbox-0.1.2.tar.gz

Download URL containerbox-0.1.2.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a87e383d8e65f58ae30576df5d6545a3e727878c2f0477b84a74eff88968166e
BLAKE2b-256 checksum
How to use checksums
726d72e5fc57a1b64392992efe7cff1a95979d374279bf5e1d0dbd41b2eb38c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 7, 2026.

Transparency log

Release files / containerbox-0.1.2-py3-none-any.whl

Download URL containerbox-0.1.2-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e46b0027c076d91d145bffb505cb5dc8daf213ffdc742ad9f3f2d9c620274d91
BLAKE2b-256 checksum
How to use checksums
57ec148b7436d619133378ec755ac115c9c66f5760843a9f7bd72ec11bd60324
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 7, 2026.

Transparency log

Security for containerbox 0.1.2

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 containerbox-0.1.2.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 7, 2026.

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.

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