Skip to main content

Python SDK for creating and managing cloud sandboxes with Excloud

Project description

Excloud Python SDK

PyPI version Python versions License: MIT

Python SDK for creating and managing cloud sandboxes with Excloud. Easily spin up isolated computing environments for development, testing, and automation.

Installation

pip install excloud

Quick Start

from excloud import Client

# Initialize client with your API key
client = Client(api_key="your_api_key_here")

# Create a sandbox
sandbox = client.create()
print(f"Sandbox created: {sandbox.id}")

# Execute commands in the sandbox
result = sandbox.run("python --version")
print(result.output)

# Clean up
sandbox.destroy()

Usage with Context Manager

For automatic cleanup, use the context manager:

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Execute commands
    result = sandbox.run("ls -la")
    print(result.output)

    # Install packages
    sandbox.run("pip install requests")

    # Run Python code
    result = sandbox.run("python -c 'import requests; print(requests.__version__)'")
    print(result.output)
# Sandbox is automatically destroyed when exiting the context

Features

  • Easy Sandbox Management: Create, manage, and destroy cloud sandboxes with simple API calls
  • Command Execution: Run shell commands and scripts in isolated environments
  • Real-time Communication: WebSocket-based real-time command execution and output streaming
  • Context Manager Support: Automatic resource cleanup with Python context managers
  • Comprehensive Error Handling: Detailed exceptions for different failure scenarios
  • Logging Support: Built-in logging for debugging and monitoring

API Reference

Client

from excloud import Client

client = Client(
    api_key="your_api_key",
    base_url="https://compute.excloud.in",  # Optional, defaults to production URL
    timeout=10  # Optional, request timeout in seconds
)

Methods

client.create()

Creates a new sandbox and returns a Sandbox instance.

client.get(sandbox_id)

Retrieves an existing sandbox by ID.

client.list()

Lists all sandboxes associated with your account.

Sandbox

sandbox.run(command)

Executes a command in the sandbox and returns the result.

result = sandbox.run("echo 'Hello, World!'")
print(result.output)  # Output from the command
print(result.exit_code)  # Exit code (0 for success)

sandbox.upload_file(local_path, remote_path)

Uploads a file from your local machine to the sandbox.

sandbox.download_file(remote_path, local_path)

Downloads a file from the sandbox to your local machine.

sandbox.destroy()

Destroys the sandbox and cleans up all resources.

Error Handling

The SDK provides specific exceptions for different error scenarios:

from excloud import Client
from excloud import (
    AuthenticationError,
    SandboxCreationError,
    CommandExecutionError,
    ConnectionError,
    SandboxNotFoundError
)

try:
    client = Client(api_key="invalid_key")
    sandbox = client.create()
except AuthenticationError:
    print("Invalid API key")
except SandboxCreationError:
    print("Failed to create sandbox")
except ConnectionError:
    print("Network connection failed")

Configuration

Environment Variables

You can also configure the client using environment variables:

export AGENTEXCLOUD_API_KEY="your_api_key"
export AGENTEXCLOUD_BASE_URL="https://compute.excloud.in"
import os
from excloud import Client

# Client will automatically use environment variables
client = Client(api_key=os.getenv("AGENTEXCLOUD_API_KEY"))

Requirements

  • Python 3.7+
  • requests>=2.25.0
  • websockets>=11.0

Examples

Running a Python Script

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Create a Python script
    script = """
import json
data = {"message": "Hello from sandbox!", "status": "success"}
print(json.dumps(data, indent=2))
"""

    # Write script to file
    sandbox.run(f"cat > script.py << 'EOF'\n{script}\nEOF")

    # Execute the script
    result = sandbox.run("python script.py")
    print(result.output)

Installing and Using Packages

from excloud import Client

client = Client(api_key="your_api_key")

with client.create() as sandbox:
    # Install packages
    sandbox.run("pip install numpy pandas")

    # Use the packages
    result = sandbox.run("python -c 'import numpy as np; print(np.__version__)'")
    print(f"NumPy version: {result.output}")

Support

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Changelog

0.1.0

  • Initial release
  • Basic sandbox creation and management
  • Command execution support
  • WebSocket-based real-time communication
  • Context manager support

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

excloud-0.1.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

excloud-0.1.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file excloud-0.1.1.tar.gz.

File metadata

  • Download URL: excloud-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for excloud-0.1.1.tar.gz
Algorithm Hash digest
SHA256 111381a36fc45f70009970cfa23ea7f2c82d5f577c0ad839a26ffd1aabfdcf14
MD5 fdaba6d4c7dbb52a4e26617c9df029b5
BLAKE2b-256 af82022b6a4d2ec816ece75132b1f1e6406a8287c06155eddc3ad0fce7762c9a

See more details on using hashes here.

File details

Details for the file excloud-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: excloud-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for excloud-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fc3ae4f647e5b66507091b9bb143c230764cb933bed31012ed1098a23015385b
MD5 15d3edcfa685edd63c4b233012342086
BLAKE2b-256 8d579d8b4fd97abf87931d6ab2f5c0868483d8453fad6d4e8ef6934f2ab0cd4a

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