Code Sandbox Python SDK
Use the Code Sandbox API to run code in 10+ languages from Python.
Install
pip install code-sandbox-sdk
Or from source in this repo:
pip install -e packages/python-sdk
Usage
Cloud (API key required):
from code_sandbox import Client
client = Client(api_key="your-api-key")
# Execute code
result = client.execute(language="python", code="print(2 + 2)")
print(result.stdout) # 4
print(result.success) # True
print(result.exit_code) # 0
# List runtimes
for r in client.runtimes():
print(r.language, r.version)
Local Piston (no API key):
from code_sandbox import create_local_client
client = create_local_client(base_url="http://localhost:2000/api/v2")
result = client.execute(language="python", code="print(2 + 2)")
print(result.stdout) # 4
# If nothing prints, check result.success, result.error, result.stderr
Troubleshooting local Piston: If result.stdout is empty, always check result.error and result.stderr — they will show the real error (e.g. "runtime is unknown" means you need to install the Python runtime inside the Piston container using the Piston CLI). Run the test script: python test_local.py (from this package directory) to see success/stdout/stderr/error.
API
- Client(api_key, base_url=None) – Create a client.
base_urldefaults tohttp://localhost:3001. - create_local_client(base_url=None) – Create a client for local Piston (Docker). No API key required.
- client.execute(language, code, stdin=None, version=None) – Run code. Returns an ExecuteResult with
success,stdout,stderr,exit_code,run_time_ms,error,compile_output. - client.runtimes() – List supported languages and versions. Returns a list of Runtime objects with
language,version,aliases.
Publishing to PyPI
For maintainers: to upload a new version to PyPI, build and upload with:
pip install build twine
python -m build
twine upload dist/* -u __token__ -p <PYPI_API_TOKEN>
PyPI API token (for later reference; keep secure, do not commit to a public repo):
pypi-AgEIcHlwaS5vcmcCJDNmM2ZlNmFmLTYxYmItNGRmYS04NDJlLWI2NzY1YWJlNjI5ZgACKlszLCJlMWZjMmY1NS05NGE0LTRmZDMtYTY0OS05MTdjMzRlMTQ4NDkiXQAABiBsLP17pnp737nYcpNRSdYRDWF8IB6vXD4BqqmjFOVRLw
Or set TWINE_USERNAME=__token__ and TWINE_PASSWORD to the token above when running twine upload dist/*.
Metadata
Release files for code-sandbox-sdk 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| code_sandbox_sdk-1.0.2.tar.gz | 4.5 kB | Without provenance | Details for code_sandbox_sdk-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| code_sandbox_sdk-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for code_sandbox_sdk-1.0.2-py3-none-any.whl |
Total release size: 9.4 kB
Release files / code_sandbox_sdk-1.0.2.tar.gz
| Download URL | code_sandbox_sdk-1.0.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dc08338a91e71b66164e02cad2339f768d10d20bcf165f6e5a15dfb4c0a0e50
|
|
BLAKE2b-256 checksum How to use checksums |
a66ba453adedcf8981aad7162319b476056d305fce00120774ff6fee07eea771
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / code_sandbox_sdk-1.0.2-py3-none-any.whl
| Download URL | code_sandbox_sdk-1.0.2-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4bb05f6baff9051dde48de47a1fbec03464893f83cdfdbda2006b96df1ba234a
|
|
BLAKE2b-256 checksum How to use checksums |
36819211a014aa90ae882353ca080cdaa886c9e293680aaf0e7e2a14618ddc82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Security for code-sandbox-sdk 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.