Skip to main content

Koyeb python sdk

This is the official Python SDK for Koyeb, a platform that allows you to deploy and manage applications and services in the cloud.

Modules

  • koyeb.api: Contains the synchronous API client and methods to interact with Koyeb's REST API. Documentation
  • koyeb.api_async: Contains the asynchronous API client (httpx-based) and methods to interact with Koyeb's REST API. Documentation
  • koyeb.sandbox: Contains the Sandbox module. Documentation

Koyeb Sanboxes

A Koyeb sandbox is an isolated, ephemeral environment designed to safely run, test, and experiment with code without affecting other systems or requiring complex setup. It provides developers with a virtualized or containerized execution space where dependencies, environment variables, and runtime contexts can be fully controlled and discarded after use.

You should use a sandbox to:

  • Execute untrusted or user-generated code securely
  • Prototype applications quickly
  • Test APIs or libraries in clean environments
  • Demonstrate functionality without configuring local infrastructure

Sandboxes are especially valuable in platforms for AI model evaluation, online coding environments, CI/CD pipelines, and educational tools that require safe, reproducible, and on-demand compute environments.

Install the SDK

pip install koyeb-sdk

Set the Koyeb API token

Using the Koyeb Python SDK requires an API token. Complete the following steps to generate the token and make it accessible to your environment:

  1. In the Koyeb control panel, navigate to Settings.
  2. Click the API tab.
  3. Click Create API token and provide a name and description. You can use the following: Name:
    sandbox-quickstart
    
    Description:
    For accessing the Koyeb Python SDK to generate sandboxes
    
  4. Click Create to complete token creation. Note that the token value will not be accessible later, so take note of it as needed.
  5. In the terminal, set the API token to be accessible to your Python environment, replacing the placeholder with your API token:
    export KOYEB_API_TOKEN="YOUR_API_TOKEN"
    

Optionally, set a default region for all sandbox deployments (defaults to "na" if not set):

export KOYEB_REGION="fra"

Optionally, send all sandbox commands and file operations to a specific sandbox gateway instead of the one the API returns (for example an in-cluster Service on a self-hosted cluster):

export KOYEB_SANDBOX_GATEWAY_URL="http://sandbox-gateway.<namespace>.svc"

Example sandbox code

See the examples directory for more basic operations.

Create a file called main.py and add the following application code:

import os
from koyeb import Sandbox

sandbox = Sandbox.create(
    image="ubuntu",
    name="file-ops",
    wait_ready=True,
)

fs = sandbox.filesystem

# Write Python script
python_code = "#!/usr/bin/env python3\nprint('Hello from Python!')\n"
fs.write_file("/tmp/script.py", python_code)
sandbox.exec("chmod +x /tmp/script.py")
result = sandbox.exec("/tmp/script.py")
print(result.stdout.strip())

sandbox.delete()

This code does the following:

  • Creates a new sandbox environment using an image of Ubuntu.
  • Creates a new Python file in the sandbox at tmp/script.py and adds a "Hello from Python" message to the file.
  • Sets the file as executable using chmod +x.
  • Executes the Python file.
  • Prints the result using stdout.
  • Deletes the sandbox.

Run the code

Use the following command to run your code:

python main.py

Your environment spins up in seconds! Then in terminal logs, you'll see the 'Hello from Python!' response.

You can also follow along in the Sandboxes tab of the Koyeb control panel to see as your sandbox environment is set up and then removed.

With Koyeb Sandboxes, you can manage fully flexible sandbox environments at scale using the Koyeb Python SDK.

The Koyeb Sandbox Python module

The Koyeb Sandbox Python module contains functionality to take any actions needed on your sanboxes, including creating and deleting sanboxes, file manipulation, running commands, managing port exposure, and more.

View the reference for the Sandbox module

View Sandboxes documentation on the Koyeb website

Metadata

Release files for koyeb-sdk 1.7.0

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

Source distribution (sdist)

Source distribution for koyeb-sdk 1.7.0
File Size Uploaded Provenance Actions
koyeb_sdk-1.7.0.tar.gz 805.5 kB Without provenance Details for koyeb_sdk-1.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for koyeb-sdk 1.7.0
File Interpreter ABI Platform Actions
koyeb_sdk-1.7.0-py3-none-any.whl Python 3 none any Details for koyeb_sdk-1.7.0-py3-none-any.whl

Total release size: 3.4 MB

Release files / koyeb_sdk-1.7.0.tar.gz

Download URL koyeb_sdk-1.7.0.tar.gz
Size 805.5 kB
Tags Source
SHA-256 checksum
How to use checksums
614457f242ef22f3d1c7a34e639d82361fadec91e61a27333be92bdfc5d5edab
BLAKE2b-256 checksum
How to use checksums
7f120ac13b69078f616c68ea857e29cc4bf8aa2fb92d1118b54230c682080f47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / koyeb_sdk-1.7.0-py3-none-any.whl

Download URL koyeb_sdk-1.7.0-py3-none-any.whl
Size 2.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
86d9110331318a6622b8c82ec07ba55a76b7186f101ff849439ba825831b2635
BLAKE2b-256 checksum
How to use checksums
8f61be6181dca50bdce21b72fb20c63e5ac318cf56c449a52540f6561bd9f0e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for koyeb-sdk 1.7.0

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