Skip to main content

Python SDK for running LLM-generated code in isolated Docker container environments

Project description

K2 Sandbox

K2 Sandbox is a Python SDK for running LLM-generated code in isolated Docker container environments. It provides a secure way to execute untrusted code with filesystem access, network capabilities, and stateful execution.

Features

  • Secure code execution in isolated Docker containers
  • Support for Python, JavaScript, and TypeScript execution
  • Stateful execution (variable persistence between runs)
  • File system operations
  • Process management
  • Terminal interaction

Installation

pip install k2-sandbox

Quick Start

from k2_sandbox import Sandbox

# Optionally, set the API base URL globally if needed
# This is useful if your API server is not at the default http://localhost:3000
# and you don't want to set it via environment variable or for every sandbox instance.
Sandbox.set_global_default_api_base_url("https://your-k2-api-server.com")

# Create and use a code interpreter sandbox
with Sandbox.create_code_interpreter() as sandbox:
    execution = sandbox.run_code("x = 41; x + 1")
    print(f"Result: {execution.text}")  # Output: 42

Documentation

For detailed documentation, see the API Reference.

License

MIT

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

k2_sandbox-0.1.1.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

k2_sandbox-0.1.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file k2_sandbox-0.1.1.tar.gz.

File metadata

  • Download URL: k2_sandbox-0.1.1.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for k2_sandbox-0.1.1.tar.gz
Algorithm Hash digest
SHA256 32d65385f2b27d3497823dd494459aebf7ca1971d272ccf0871e29144517a52a
MD5 e6a9f9dd8be6983ae94933f1b757d352
BLAKE2b-256 ffd835fb05162ab9683c59ac71125828edf4429ee5b9c3ca9af72e6bdb140344

See more details on using hashes here.

File details

Details for the file k2_sandbox-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: k2_sandbox-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for k2_sandbox-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66ede71110ba2461a2484e5a5bc8b2dd35fd508313cb1617e628650a83cd60a3
MD5 834e6c586f63f4a0966030a698821baf
BLAKE2b-256 96e6b4139a5f954adbf0b14ab2f0a03b3b857059c94aa33c5c58aad382ed92d9

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