Together Sandbox Python SDK
Project description
together-sandbox (Python)
Developer guide for the together-sandbox Python SDK.
Note: The generated OpenAPI clients (
together_sandbox/api/andtogether_sandbox/sandbox/) are committed to the repository temporarily until the package is published to PyPI. Once published they will be removed from version control and regenerated as part of the install/build step instead.
Generating the OpenAPI clients
The SDK wraps two auto-generated OpenAPI clients. Regenerate them whenever an OpenAPI spec changes (both specs live in the repo root):
# From the repo root
bash generate.sh
This runs together-sandbox-python/generate.sh which invokes
openapi-python-client against api-openapi.json and sandbox-openapi.json
and writes the output to:
together_sandbox/api/— management API clienttogether_sandbox/sandbox/— in-VM sandbox API client
Never edit those directories by hand — they are overwritten on every run.
Tests
Prerequisites
- Together AI API key
- Python 3.10 or higher
- Install dev dependencies:
cd together-sandbox-python
pip install .[dev]
- Set up a virtual environment (optional but recommended):
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Create a snapshot to run the tests with
node ./together-sandbox-cli/dist/together-sandbox.mjs snapshots create --context ./test-template
Environment Variables
Set the following environment variables before running e2e tests:
# Required
export TOGETHER_API_KEY="your-api-key-here"
# Optional
export TOGETHER_SNAPSHOT_ID="snapshot-id" # If you want to test with a specific snapshot
export TOGETHER_BASE_URL="https://api.codesandbox.io" # Override default base URL
Running Tests
Note: All pytest commands must be run from the together-sandbox-python/ directory.
Unit tests
pytest tests/ -v
Run all e2e tests
pytest tests/e2e/ -v
Run specific e2e test file
pytest tests/e2e/test_sandbox_filesystem.py -v
Run specific test class or function
# Run a specific test class
pytest tests/e2e/test_sandbox_filesystem.py::TestSandboxFilesystem -v
# Run a specific test function
pytest tests/e2e/test_sandbox_filesystem.py::TestSandboxFilesystem::test_write_and_read_text_file -v
Run with output from print statements
pytest tests/e2e/ -v -s
Test Structure
Fixtures (e2e/helpers.py)
The helpers.py module provides pytest fixtures that handle sandbox lifecycle:
sdk: Provides a configuredTogetherSandboxinstancesandbox: Creates a sandbox instance and automatically cleans it up after testsretry_until: Helper function for polling operations
Example usage in tests:
@pytest.mark.asyncio
async def test_something(sandbox: Sandbox):
# sandbox is automatically created and will be cleaned up
await sandbox.files.create_file("/test.txt", "content")
result = await sandbox.files.read_file("/test.txt")
assert result.content == "content"
Test Patterns
Using the sandbox fixture
Most tests should use the sandbox fixture which handles creation and cleanup:
async def test_my_feature(sandbox: Sandbox):
# Your test code here
# Sandbox will be automatically cleaned up
pass
Manual sandbox management
For lifecycle tests that need explicit control:
async def test_lifecycle():
sdk = TogetherSandbox(api_key=get_api_key())
try:
sandbox = await sdk.sandboxes.start(template_id)
# Test code
finally:
await sdk.sandboxes.shutdown(sandbox.id)
await sdk.close()
Retry polling pattern
For operations that may take time:
from .helpers import retry_until
result = await retry_until(
lambda: sandbox.files.read_file("/path"),
lambda r: r.content == "expected",
timeout=5.0,
interval=0.1
)
Notes
- E2E tests connect to real sandbox instances and may incur API costs
- Tests automatically clean up sandboxes, but interrupted tests may leave orphaned sandboxes
- Some exec tests are placeholders and may need implementation based on the actual API structure
- Binary file tests verify the application/octet-stream content type handling
- Timeout for sandbox cleanup is set to 10 seconds to prevent hanging
Troubleshooting
Tests skip with "TOGETHER_API_KEY environment variable not set"
Make sure you've exported the TOGETHER_API_KEY environment variable:
export TOGETHER_API_KEY="your-api-key"
Tests fail with timeout errors
The sandbox may be taking longer to start or respond. You can:
- Check your network connection
- Verify the API service status
- Increase timeout values in the tests if needed
Tests fail with authentication errors
Verify your API key is valid and has the necessary permissions for:
- Creating sandboxes
- Reading/writing files
- Managing sandbox lifecycle
Orphaned sandboxes
If tests are interrupted, sandboxes may not be cleaned up. You can manually delete them using the API or wait for automatic cleanup policies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file together_sandbox-1.11.0.tar.gz.
File metadata
- Download URL: together_sandbox-1.11.0.tar.gz
- Upload date:
- Size: 68.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6831ff743e96849e86e3f8c9b3460bf1d5b8d7bd4c60a80e18b6b120ac75f63b
|
|
| MD5 |
c235d75df63ba65ddf0db41a01da6c20
|
|
| BLAKE2b-256 |
192c5c625aff9da07aa16d7f4acee0ebb1a30765b06d368148560700d8bff8ac
|
Provenance
The following attestation bundles were made for together_sandbox-1.11.0.tar.gz:
Publisher:
release.yml on togethercomputer/together-sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
together_sandbox-1.11.0.tar.gz -
Subject digest:
6831ff743e96849e86e3f8c9b3460bf1d5b8d7bd4c60a80e18b6b120ac75f63b - Sigstore transparency entry: 1653097075
- Sigstore integration time:
-
Permalink:
togethercomputer/together-sandbox@18e22f1532676071162e1169fa4af4fab07a08ea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/togethercomputer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@18e22f1532676071162e1169fa4af4fab07a08ea -
Trigger Event:
push
-
Statement type:
File details
Details for the file together_sandbox-1.11.0-py3-none-any.whl.
File metadata
- Download URL: together_sandbox-1.11.0-py3-none-any.whl
- Upload date:
- Size: 151.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff80cca68989fc423ca039909ee0612f57885358d04289c8d85231966817b06b
|
|
| MD5 |
0f2954964acb3aee64c97108c45fd5e2
|
|
| BLAKE2b-256 |
8a3f70514f9e0a1a636d3eb456987c6cc627ecd80b635584aaec7407293d145b
|
Provenance
The following attestation bundles were made for together_sandbox-1.11.0-py3-none-any.whl:
Publisher:
release.yml on togethercomputer/together-sandbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
together_sandbox-1.11.0-py3-none-any.whl -
Subject digest:
ff80cca68989fc423ca039909ee0612f57885358d04289c8d85231966817b06b - Sigstore transparency entry: 1653097243
- Sigstore integration time:
-
Permalink:
togethercomputer/together-sandbox@18e22f1532676071162e1169fa4af4fab07a08ea -
Branch / Tag:
refs/heads/main - Owner: https://github.com/togethercomputer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@18e22f1532676071162e1169fa4af4fab07a08ea -
Trigger Event:
push
-
Statement type: