Skip to main content

Add your description here

Project description

open-sandboxes

open-sandboxes is an open-source, python-native and self-hosted-first alternative implementation of Cloudflare Sandbox SDK.

The only pre-requisite for running open-sandboxes is to have a cloud environment with Docker installed: whenever you want to execute python code remotely, you will simply leverage a Sandbox object which will create an ephemeral Docker container (based on ghcr.io/astral-sh/uv:alpine) on your remote machine, on which all the dependencies will be installed and the code will run.

Installation

You can install open-sandboxes via pip:

pip install open-sandboxes

Or you can build it from source code:

git clone https://github.com/AstraBert/open-sandboxes
cd open-sandboxes
pip install [-e] . # use the -e option for editable installations

Usage

To create a Sandbox instance, you need an SSH remote connection and a pyproject.toml file with all your dependencies listed. This can be provided:

  1. With the path to the pyproject.toml file and a SSHConnection object:
from open_sandboxes import Sandbox
from open_sandboxes.ssh_connection import SSHConnection

conn = SSHConnection(
    host="your-host.com",
    username="user",
    password="my-password",  # you can also use a passphrase with a private key file
    port=22,
)
sandbox = Sandbox(
    name="sandbox-1",
    remote_connection=conn,
    pyproject_file_path="pyproject.toml",
)
  1. With a PyprojectConfig instance:
from open_sandboxes import Sandbox
from open_sandboxes.ssh_connection import SSHConnection
from open_sandboxes.uv_config import PyprojectConfig

conn = SSHConnection(
    host="your-host.com",
    username="user",
    password="my-password",  # you can also use a passphrase with a private key file
    port=22,
)
config = PyprojectConfig(
    dependencies=[{"name": "httpx", "version_constraints": "<1"}],
    title="http-server",
    min_python_version="3.10",  # included (>=3.10)
    max_python_version="3.13",  # excluded (<3.13)
)
sandbox = Sandbox(name="sandbox-1", remote_connection=conn, config=config)
  1. Using the from_connection_args class method:
sandbox = Sandbox.from_connection_args(
    name="sandbox-1",
    username="user",
    passphrase="secret-passhprase",
    key_file=".ssh/key_file",
    host="your-host.com",
    port=22,
    pyproject_file_path="pyproject.toml",
)

Once you created a Sandbox instance, use the run_code method to run whatever code you want:

code = """
import httpx
import asyncio

async def main():
    async with httpx.AsyncClient() as client:
        res = await client.get("https://uselessfacts.jsph.pl/api/v2/facts/random")
        res.raise_for_status()
        return res.json().get("text", "no text")

if __name__ == "__main__":
    result = asyncio.run(main())
    print(f"A random fact is: {result}")
"""

res = sandbox.run_code(code=code)
print("Code output:", res["output"])
print("Captured stderr logs:", res["error"])

Contributing

Contributions are always welcome! Please read the contributing guide to get to know more about the contribution process.

License

This project is provided under an MIT License

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

open_sandboxes-0.1.0a0.tar.gz (35.2 kB view details)

Uploaded Source

Built Distribution

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

open_sandboxes-0.1.0a0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file open_sandboxes-0.1.0a0.tar.gz.

File metadata

  • Download URL: open_sandboxes-0.1.0a0.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for open_sandboxes-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 103f03f9f1b4f8d6cfb4fc27c38a2f0d24a3cc9f57369acb03cdb91aa5e1b743
MD5 51dd90ce75434fb09abf21eb503eb353
BLAKE2b-256 210d377f36ab82367b9907bc94bd24804c7cb50394ba02b58bc3ca9e71736606

See more details on using hashes here.

File details

Details for the file open_sandboxes-0.1.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for open_sandboxes-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 45c4a798fc886a8c63b17bfa542d79204634b9cbe957d0fdf9552e676dd59d7a
MD5 734fe25526d5563cffa112cc60b654e8
BLAKE2b-256 805287c6481782bdd0554578f2125906bec5dbd41e35c37e0da99d258d1f55bf

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