Skip to main content

Deno Sandbox Python SDK

Project description

Deno Sandbox Python SDK

The official Python SDK for Deno Sandboxes - isolated, secure environments running in lightweight Linux microVMs. Create on-demand sandboxes to execute untrusted code, run shell commands, build AI agents with code execution capabilities, or provide interactive development environments.

Key Features

  • Secure Isolation - Each sandbox runs in its own microVM with full process and filesystem isolation
  • Sync & Async APIs - First-class support for both synchronous and asynchronous Python code
  • Process Management - Spawn and manage shell processes with full stdin/stdout/stderr control
  • Deno Runtime - Execute TypeScript/JavaScript code, run Deno scripts, or interact with a REPL
  • Filesystem Operations - Read, write, copy, and traverse files with a comprehensive filesystem API
  • Persistent Storage - Create volumes and snapshots to persist data across sandbox sessions
  • App Management - Create and manage Deno Deploy apps, revisions, and deployment timelines
  • HTTP & SSH Exposure - Expose sandbox services to the internet via HTTP or SSH
  • Network Controls - Fine-grained control over outbound network access with allowlists
  • File Transfers - Upload files from your local machine or download from the sandbox
  • Configurable Resources - Adjust memory limits, timeouts, and select deployment regions

Installation

pip install deno-sandbox

Or with uv:

uv add deno-sandbox

Requirements

  • Python 3.10+
  • A Deno Deploy access token (set as DENO_DEPLOY_TOKEN environment variable)

Quick Start

Synchronous API

from deno_sandbox import DenoDeploy

sdk = DenoDeploy()

with sdk.sandbox.create() as sb:
    # Run a shell command
    process = sb.spawn("echo", args=["Hello from the sandbox!"])
    process.wait()

    # Write and read files
    sb.fs.write_text_file("/tmp/example.txt", "Hello, World!")
    content = sb.fs.read_text_file("/tmp/example.txt")
    print(content)

Asynchronous API

import asyncio
from deno_sandbox import AsyncDenoDeploy

async def main():
    sdk = AsyncDenoDeploy()

    async with sdk.sandbox.create() as sb:
        # Run a shell command
        process = await sb.spawn("echo", args=["Hello from the sandbox!"])
        await process.wait()

        # Write and read files
        await sb.fs.write_text_file("/tmp/example.txt", "Hello, World!")
        content = await sb.fs.read_text_file("/tmp/example.txt")
        print(content)

asyncio.run(main())

Usage Examples

Execute TypeScript/JavaScript with Deno

with sdk.sandbox.create() as sb:
    # Run inline TypeScript code
    result = sb.deno.eval("console.log('Hello from Deno!')")

    # Or run a script file
    sb.fs.write_text_file("/app/server.ts", '''
        Deno.serve({ port: 8000 }, () => new Response("Hello!"));
    ''')
    process = sb.deno.run(entrypoint="/app/server.ts")

Interactive Deno REPL

with sdk.sandbox.create() as sb:
    repl = sb.deno.repl()

    # Evaluate expressions and get results
    result = repl.eval("1 + 1")
    print(result)  # 2

    result = repl.eval("const x = [1, 2, 3]; x.map(n => n * 2)")
    print(result)  # [2, 4, 6]

    repl.close()

Filesystem Operations

with sdk.sandbox.create() as sb:
    # Create directories
    sb.fs.mkdir("/app/data", recursive=True)

    # Write files
    sb.fs.write_text_file("/app/data/config.json", '{"key": "value"}')
    sb.fs.write_file("/app/data/binary.bin", b"\x00\x01\x02\x03")

    # Read files
    text = sb.fs.read_text_file("/app/data/config.json")
    binary = sb.fs.read_file("/app/data/binary.bin")

    # List directory contents
    entries = sb.fs.read_dir("/app/data")
    for entry in entries:
        print(f"{entry['name']} - is_file: {entry['is_file']}")

    # Walk directory tree
    for entry in sb.fs.walk("/app"):
        print(entry["path"])

    # Glob pattern matching
    matches = sb.fs.expand_glob("**/*.json", root="/app")

Upload and Download Files

with sdk.sandbox.create() as sb:
    # Upload a local file or directory to the sandbox
    sb.fs.upload("./local/project", "/app/project")

    # Run a build process
    process = sb.spawn("npm", args=["run", "build"], cwd="/app/project")
    process.wait()

    # Download results
    sb.fs.download("./output", "/app/project/dist")

Persistent Volumes

# Create a volume for persistent storage
volume = sdk.volumes.create(
    slug="my-data",
    region="us-east-1",
    capacity="1GB"
)

# Use the volume in a sandbox
with sdk.sandbox.create(volumes={"/data": volume["id"]}) as sb:
    sb.fs.write_text_file("/data/persistent.txt", "This data persists!")

# Create a snapshot of the volume
snapshot = sdk.volumes.snapshot(volume["id"], slug="my-snapshot")

Expose HTTP Services

with sdk.sandbox.create() as sb:
    # Start a web server
    sb.fs.write_text_file("/app/server.ts", '''
        Deno.serve({ port: 8000 }, (req) => {
            return new Response("Hello from sandbox!");
        });
    ''')
    process = sb.deno.run(entrypoint="/app/server.ts")
    process.wait_http_ready()

    # Expose it publicly
    url = sb.expose_http(port=8000)
    print(f"Server available at: {url}")

Configure Sandbox Options

with sdk.sandbox.create(
    region="us-east-1",              # Deploy region
    memory_mb=2048,                  # Memory limit (default: 1280 MB)
    timeout="5m",                    # Auto-shutdown timeout
    env={"NODE_ENV": "production"},  # Environment variables
    allow_net=["api.example.com"],   # Network allowlist
) as sb:
    process = sb.spawn("node", args=["app.js"])
    process.wait()

Manage Apps and Deployments

# Create a new app
app = sdk.apps.create(slug="my-app")
print(f"Created app: {app['slug']}")

# List all apps
for app in sdk.apps.list():
    print(f"App: {app['slug']} (created: {app['created_at']})")

# Get revisions for an app
revisions = sdk.revisions.list("my-app")
for rev in revisions:
    print(f"Revision: {rev['id']} - Status: {rev['status']}")

# List timelines (deployment targets) for an app
timelines = sdk.timelines.list("my-app")
for timeline in timelines:
    print(f"Timeline: {timeline['slug']}")
    for domain in timeline["domains"]:
        print(f"  Domain: {domain['domain']}")

# Update or delete an app
sdk.apps.update("my-app", slug="renamed-app")
sdk.apps.delete("renamed-app")

API Reference

DenoDeploy / AsyncDenoDeploy

The main entry point for the SDK. Provides access to:

  • sandbox - Create and manage sandbox instances
  • volumes - Create and manage persistent volumes
  • snapshots - List and manage volume snapshots
  • apps - Create and manage Deno Deploy applications
  • revisions - List and inspect app revisions
  • timelines - List deployment timelines and domains

Sandbox

A running sandbox instance with:

  • spawn(command, args, ...) - Spawn a child process
  • fs - Filesystem operations (read, write, mkdir, walk, etc.)
  • deno - Deno runtime (run scripts, REPL, eval)
  • env - Environment variable management
  • expose_http(port) - Expose HTTP service publicly
  • expose_ssh() - Expose SSH access
  • fetch(url) - Make HTTP requests from within the sandbox
  • extend_timeout(seconds) - Extend the sandbox timeout
  • kill() - Terminate the sandbox

Apps

Manage Deno Deploy applications:

  • create(slug) - Create a new app
  • get(id_or_slug) - Get app by ID or slug
  • list() - List all apps
  • update(app, slug) - Update an app
  • delete(app) - Delete an app

Revisions

Track deployment revisions:

  • get(app, id) - Get a specific revision
  • list(app) - List revisions for an app

Timelines

Manage deployment timelines:

  • list(app) - List timelines for an app (includes domains)

License

MIT - see the LICENSE file for details.

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

deno_sandbox-0.6.1.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

deno_sandbox-0.6.1-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file deno_sandbox-0.6.1.tar.gz.

File metadata

  • Download URL: deno_sandbox-0.6.1.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for deno_sandbox-0.6.1.tar.gz
Algorithm Hash digest
SHA256 f1000d737a37df274833f8f4fc4100ff3534b056ed768f4dc354fa72f5b8d8b8
MD5 8e6dd120f3690d4e4bde5ede3950b7f8
BLAKE2b-256 17766bd87f33f5bebdc6b51d4260f5ca2dfaeecf8a6c023a5dd215afaa3d85ae

See more details on using hashes here.

File details

Details for the file deno_sandbox-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: deno_sandbox-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for deno_sandbox-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bdf5522d6b2f8078c2b3b2a45663d0dcb4b8f145f0c6251b18f6e9569531ab9
MD5 5f7d59e7fd6a2855a44c02dc3a72c50d
BLAKE2b-256 ad9b2df789dad19a5024bbca28c0ea9c82a3e0b1dd617da0c4c5e0e044803720

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