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 URL 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_default_api_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.2.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.2-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: k2_sandbox-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 feaa99ad68a389044063640489f96f527c2e706e0a9fded1dc771153e182cdcf
MD5 d0a1a18f55cea892bface146a58b3ada
BLAKE2b-256 dc1b41c7dbe577bb067a6938f82458b35f74193a22865bf3a9d78f546b1c63e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: k2_sandbox-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed159ceb9d44b3fdf6e99c03d75fa8f39e0d59ddf69c9c0c0b409d6534bc4946
MD5 31cf7eb4f53e2534b0520b6b51ceb481
BLAKE2b-256 c8fe419d157ce3e7b5cad617149697f8c14873674260ed7531db3f4b9d7f6ae3

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