Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.


title: "GMI Sandbox SDK Usage" description: "Install, configure, and use the GMI Sandbox Python SDK."

GMI Sandbox SDK Usage

Install

python -m pip install gmi-sandbox-sdk

Configure

Use environment variables or pass values directly.

To get an API key, log in to https://console.gmicloud.ai/, click API keys, select compute, and click Create API key.

export GMI_SANDBOX_API_KEY="your-api-key"

GMI_SANDBOX_IDC_NAME is optional. Leave it unset to use your organization's default IDC. Set it only when you want requests to target a non-default IDC:

export GMI_SANDBOX_IDC_NAME="gmi-sandbox-us"

Create a client

from sandbox_sdk import SandboxClient

client = SandboxClient()

You can also pass credentials explicitly:

client = SandboxClient(
    api_key="your-api-key",
)

Create and use a sandbox

sandbox = client.sandboxes.create(
    template_id="template-id",
)

sandbox.connect()
result = sandbox.commands.run("echo hello", wait=True)
print(result.stdout)

sandbox.files.write("/tmp/hello.txt", "hello")
print(sandbox.files.read("/tmp/hello.txt").decode())

sandbox.delete()

If you already have a sandbox ID:

sandbox = client.sandboxes.get("sandbox-id")
sandbox.connect()

Files

sandbox.files.read("/tmp/a.txt")
sandbox.files.write("/tmp/a.txt", "hello")
sandbox.files.write("/tmp/a.bin", b"binary-data")
sandbox.files.upload("./local.txt", "/workspace/local.txt")
sandbox.files.download("/workspace/output.txt", "./output.txt")

download() returns bytes and can also write to a destination path.

Commands

execution = sandbox.commands.run(
    "python --version",
    cwd="/workspace",
    envs={"PYTHONUNBUFFERED": "1"},
    wait=True,
    wait_timeout_seconds=25,
)

print(execution.status)
print(execution.exit_code)
print(execution.stdout)
print(execution.stderr)

You can refresh or cancel a running execution:

execution.refresh()
execution.cancel()

Templates

template = client.templates.get("template-id")
template.update(name="new-name")
template.delete()

builds = template.builds()
build = template.build("build-id")
logs = template.build_logs("build-id", offset=0, limit=100)

Creating a template requires an idempotency key:

template = client.templates.create(
    name="demo",
    resources={"type": "preset", "product": "gmi.sandbox.small"},
    build={"source": {"type": "image", "image": "ubuntu:22.04"}},
    idempotency_key="template-1",
)

print(template.template_id)
template.update(name="new-name")

Product specifications

client.product_specifications.list()
client.product_specifications.list(idc_name="gmi-sandbox-us")

Errors

The SDK raises typed exceptions for HTTP failures:

  • BadRequestError
  • AuthenticationError
  • PermissionDeniedError
  • NotFoundError
  • ConflictError
  • RateLimitError
  • ServerError

Example:

from sandbox_sdk import NotFoundError

try:
    client.sandboxes.get("missing")
except NotFoundError:
    print("sandbox not found")

Metadata

Release files for gmi-sandbox-sdk 0.2.0b4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gmi-sandbox-sdk 0.2.0b4
File Size Uploaded Provenance Actions
gmi_sandbox_sdk-0.2.0b4.tar.gz 11.3 kB Without provenance Details for gmi_sandbox_sdk-0.2.0b4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gmi-sandbox-sdk 0.2.0b4
File Interpreter ABI Platform Actions
gmi_sandbox_sdk-0.2.0b4-py3-none-any.whl Python 3 none any Details for gmi_sandbox_sdk-0.2.0b4-py3-none-any.whl

Total release size: 21.5 kB

Release files / gmi_sandbox_sdk-0.2.0b4.tar.gz

Download URL gmi_sandbox_sdk-0.2.0b4.tar.gz
Size 11.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9c7d3547bd4d5a6d1b19aa298d2f8828a31fcc596e9513369cdd4f95f20a93da
BLAKE2b-256 checksum
How to use checksums
1803d2146b9a43fda5f8b92a475250c0d262c776a3c5e9cbc5c21935dfdf214b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / gmi_sandbox_sdk-0.2.0b4-py3-none-any.whl

Download URL gmi_sandbox_sdk-0.2.0b4-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13f4625b632fbe466f636ed7be4e932ecdb8e1e75e5512833d463aad7f1cc08d
BLAKE2b-256 checksum
How to use checksums
fb9c629a666ed553fdad27ce2469857225c282e3c86ae294979285a515d3b0e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for gmi-sandbox-sdk 0.2.0b4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page