Minimal Docker-only sandbox for executing code
Project description
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:
stdoutstderrexit_codetimed_outduration_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)
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 containerbox-0.1.2.tar.gz.
File metadata
- Download URL: containerbox-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a87e383d8e65f58ae30576df5d6545a3e727878c2f0477b84a74eff88968166e
|
|
| MD5 |
bc1f93470bc4000a8c34bae2b57ecbd8
|
|
| BLAKE2b-256 |
726d72e5fc57a1b64392992efe7cff1a95979d374279bf5e1d0dbd41b2eb38c4
|
Provenance
The following attestation bundles were made for containerbox-0.1.2.tar.gz:
Publisher:
publish.yml on pushpitkamboj/containerbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
containerbox-0.1.2.tar.gz -
Subject digest:
a87e383d8e65f58ae30576df5d6545a3e727878c2f0477b84a74eff88968166e - Sigstore transparency entry: 1750700329
- Sigstore integration time:
-
Permalink:
pushpitkamboj/containerbox@41a4edff9db64e5ff760ece5efb8042222e56fa2 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/pushpitkamboj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41a4edff9db64e5ff760ece5efb8042222e56fa2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file containerbox-0.1.2-py3-none-any.whl.
File metadata
- Download URL: containerbox-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e46b0027c076d91d145bffb505cb5dc8daf213ffdc742ad9f3f2d9c620274d91
|
|
| MD5 |
021e75bad2e144e14303b49df47d2474
|
|
| BLAKE2b-256 |
57ec148b7436d619133378ec755ac115c9c66f5760843a9f7bd72ec11bd60324
|
Provenance
The following attestation bundles were made for containerbox-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on pushpitkamboj/containerbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
containerbox-0.1.2-py3-none-any.whl -
Subject digest:
e46b0027c076d91d145bffb505cb5dc8daf213ffdc742ad9f3f2d9c620274d91 - Sigstore transparency entry: 1750700415
- Sigstore integration time:
-
Permalink:
pushpitkamboj/containerbox@41a4edff9db64e5ff760ece5efb8042222e56fa2 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/pushpitkamboj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@41a4edff9db64e5ff760ece5efb8042222e56fa2 -
Trigger Event:
release
-
Statement type: