Nightona Python SDK
The official Python SDK for Nightona, a secure and elastic infrastructure for running AI-generated code. Nightona provides full composable computers — sandboxes — that you can manage programmatically using the Nightona SDK.
The SDK provides an interface for sandbox management, file system operations, Git operations, language server protocol support, process and code execution, and computer use. For more information, see the documentation.
Installation
Install the package using pip:
pip install nightona
Get API key
Generate an API key from the Nightona Dashboard ↗ to authenticate SDK requests and access Nightona services. For more information, see the API keys documentation.
Configuration
Configure the SDK using environment variables or by passing a configuration object:
NIGHTONA_API_KEY: Your Nightona API keyNIGHTONA_API_URL: The Nightona API URLNIGHTONA_TARGET: Your target region environment (e.g.us,eu)
from nightona import Nightona, NightonaConfig
# Initialize with environment variables
nightona = Nightona()
# Initialize with configuration object
config = NightonaConfig(
api_key="YOUR_API_KEY",
api_url="YOUR_API_URL",
target="us"
)
Create a sandbox
Create a sandbox to run your code securely in an isolated environment.
from nightona import Nightona, NightonaConfig
config = NightonaConfig(api_key="YOUR_API_KEY")
nightona = Nightona(config)
sandbox = nightona.create()
response = sandbox.process.code_run('print("Hello World")')
Examples and guides
Nightona provides examples and guides for common sandbox operations, best practices, and a wide range of topics, from basic usage to advanced topics, showcasing various types of integrations between Nightona and other tools.
Create a sandbox with custom resources
Create a sandbox with custom resources (CPU, memory, disk).
from nightona import Nightona, CreateSandboxFromImageParams, Image, Resources
nightona = Nightona()
sandbox = nightona.create(
CreateSandboxFromImageParams(
image=Image.debian_slim("3.12"),
resources=Resources(cpu=2, memory=4, disk=8)
)
)
Create an ephemeral sandbox
Create an ephemeral sandbox that is automatically deleted when stopped.
from nightona import Nightona, CreateSandboxFromSnapshotParams
nightona = Nightona()
sandbox = nightona.create(
CreateSandboxFromSnapshotParams(ephemeral=True, auto_stop_interval=5)
)
Create a sandbox from a snapshot
Create a sandbox from a snapshot.
from nightona import Nightona, CreateSandboxFromSnapshotParams
nightona = Nightona()
sandbox = nightona.create(
CreateSandboxFromSnapshotParams(
snapshot="my-snapshot-name",
language="python"
)
)
Execute Commands
Execute commands in the sandbox.
# Execute a shell command
response = sandbox.process.exec('echo "Hello, World!"')
print(response.result)
# Run Python code
response = sandbox.process.code_run('''
x = 10
y = 20
print(f"Sum: {x + y}")
''')
print(response.result)
File Operations
Upload, download, and search files in the sandbox.
# Upload a file
sandbox.fs.upload_file(b'Hello, World!', 'path/to/file.txt')
# Download a file
content = sandbox.fs.download_file('path/to/file.txt')
# Search for files
matches = sandbox.fs.find_files(root_dir, 'search_pattern')
Git Operations
Clone, list branches, and add files to the sandbox.
# Clone a repository
sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')
# List branches
branches = sandbox.git.branches('path/to/repo')
# Add files
sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])
Language Server Protocol
Create and start a language server to get code completions, document symbols, and more.
# Create and start a language server
lsp = sandbox.create_lsp_server('python', 'path/to/project')
lsp.start()
# Notify the lsp for the file
lsp.did_open('path/to/file.py')
# Get document symbols
symbols = lsp.document_symbols('path/to/file.py')
# Get completions
completions = lsp.completions('path/to/file.py', {"line": 10, "character": 15})
Code in _sync directory shouldn't be edited directly. It should be generated from the corresponding async code in the _async directory using the SDK generation scripts in the scripts directory.
Metadata
Release files for nightona 0.191.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nightona-0.191.0.tar.gz | 146.1 kB | Without provenance | Details for nightona-0.191.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nightona-0.191.0-py3-none-any.whl | Python 3 | none | any | Details for nightona-0.191.0-py3-none-any.whl |
Total release size: 323.8 kB
Release files / nightona-0.191.0.tar.gz
| Download URL | nightona-0.191.0.tar.gz |
|---|---|
| Size | 146.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec6a0365483f55af576a61e4abb6cf17d2cdfe3ad27b8e2324dd3a4aa452e972
|
|
BLAKE2b-256 checksum How to use checksums |
9b33304b50483bec0b1655bc58ba932a6546642d5f40252cbcff199fd9f3d757
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / nightona-0.191.0-py3-none-any.whl
| Download URL | nightona-0.191.0-py3-none-any.whl |
|---|---|
| Size | 177.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
53e80751f0abd9eb55a9faa5cf9edb30fa909be921a0a01748de035ae2b14f02
|
|
BLAKE2b-256 checksum How to use checksums |
ff7e03687fc38030ba4be2e8db28543f3a258dcd9e6bab69430d0c71ce4e6769
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for nightona 0.191.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.