Installation

Get started with cloudcode SDK in just a few simple steps.

Quick Examples

Local SDK

The Local SDK provides AI coding in your local environment:

from cloudcode import Local
import os

cwd = os.getcwd()

# Initialize the SDK with your project directory and API keys
# This must be a git repository if use_git=True (default)
sdk = Local(
    working_dir=cwd,
    api_key=os.getenv("CLOUD_CODE_API_KEY")
)

# Create a new file with content
sdk.create_file(
    "src/calculator.py", # specify file path
    """def add(a, b):
    return a + b

def subtract(a, b):
    return a - b
"""
)

# Run an AI coding task to improve the calculator
result = sdk.code(
    prompt="Add a multiply and divide function to the calculator.py file. Make sure to handle division by zero in the divide function.",
    editable_files=["src/calculator.py"],
    readonly_files=[]
)

# Check if the operation was successful
if result["success"]:
    print("Coding task was successful!")
    print("Changes made:")
    print(result["diff"])
else:
    print("Coding task failed or made no meaningful changes.")

# To check what content is now in the file after the AI changes
updated_content = sdk.read_file("src/calculator.py")
print("Updated file content:", updated_content)

Sandbox SDK

The SandboxSDK allows you to run code safely in a remote environment:

from cloudcode import SandboxSDK
import os

# Initialize the SDK
sdk = SandboxSDK(
    model="gpt-4.1",
    api_key=os.getenv("CLOUDCODE_API_KEY"),
    sandbox_timeout=180  # 3 minutes (in seconds)
)

# Check sandbox info
info = sdk.get_sandbox_info()
print(f"Sandbox created with ID: {info['sandbox_id']}")
print(f"Expires at: {info['end_at']}")

# Create a file in the sandbox
sdk.create_file(
    "test.py",
    """def add(a, b):
    return a + b

print(add(5, 3))
"""
)

# Run the file
result = sdk.run_command("python3 test.py")
print(result["stdout"])  # Outputs: 8

# Use AI to improve the code
sdk.sandbox_code(
    prompt="Add subtract and multiply functions with proper error handling",
    editable_files=["/home/user/test.py"]
)

# Download the improved file
sdk.download_file("/home/user/test.py", "local_test.py")

# Shut down the sandbox when done
sdk.kill_sandbox()

Next Steps