Skip to main content

SQLsaber sandbox plugin

sqlsaber-sandbox runs Python analysis in a persistent local or remote sandbox. Give the analysis agent a goal and input files. It runs code and returns findings, plots, and generated files.

Configure the CLI

Install the plugin with the extra for your provider. This example installs E2B:

uv tool install --with 'sqlsaber-sandbox[e2b]' sqlsaber
saber plugins setup sandbox

The setup command requires an explicit provider. SQLsaber does not select a cloud provider from the credentials it finds. The command stores secrets in the OS credential store and saves non-secret settings separately.

E2B_API_KEY, DAYTONA_API_KEY, MODAL_TOKEN_ID, MODAL_TOKEN_SECRET, and SPRITES_TOKEN override saved credentials. DAYTONA_API_URL overrides the saved Daytona endpoint. You can also set SQLSABER_SANDBOX_PROVIDER to select the provider for the current process.

For Modal, leave both token fields blank to use Modal's native authentication. Run modal token new first if Modal is not configured. Remote providers receive the query results and files selected for analysis, and provider charges may apply.

Start an SDK session

Select a provider with SandboxConfig. Pass input files through Workspace:

from pathlib import Path

from pydantic_ai.usage import UsageLimits
from sqlsaber_sandbox import SandboxConfig, SandboxSession, Workspace

config = SandboxConfig(provider="e2b", idle_seconds=300, max_lifetime_seconds=900)

async with SandboxSession(
    model="anthropic:claude-sonnet-4-6",
    config=config,
) as session:
    first = await session.analyze(
        "Fit a trend and save a plot",
        workspace=Workspace.from_files([("sales.csv", Path("sales.csv").read_bytes())]),
        usage_limits=UsageLimits(request_limit=12),
    )
    follow_up = await session.analyze(
        "Use the same fitted model to explain the final month",
        usage_limits=UsageLimits(request_limit=6),
    )

Reuse the session for follow-up goals. Variables, installed packages, generated files, and the analysis agent's history remain available until the session closes. The async with block closes the sandbox on exit.

Pass usage_limits to limit model requests for each analyze call. To run Python without a model request, call await session.execute(code, workspace=...).

Save analysis files

Ask the analysis agent to save deliverables in its working directory. The returned AnalysisResult contains notebook bytes and generated files, including plots and model weights. To export the current state without running another cell, call await session.snapshot().

Pass the result to your application's ArtifactStore to publish the files. The result remains usable after the session closes:

from sqlsaber.artifacts import ArtifactContext
from sqlsaber_sandbox import publish_analysis

publication = await publish_analysis(
    follow_up,
    store=artifact_store,
    context=ArtifactContext(conversation_id="conversation-123"),
)

Add sandbox analysis to SQLsaber

Register the capability through SQLSaberOptions.capabilities. Pass your query result store and artifact store to share SQL inputs and retain generated files:

from functools import partial

from sqlsaber import SQLSaber, SQLSaberOptions
from sqlsaber_sandbox import SandboxConfig, capability

options = SQLSaberOptions(
    database="analytics",
    query_result_store=query_result_store,
    artifact_store=artifact_store,
    capabilities=[
        partial(
            capability,
            config=SandboxConfig(provider="e2b"),
            model_name="openai:gpt-5-mini",
            api_key="application-managed-key",
        ),
    ],
)

async with SQLSaber(options=options) as saber:
    result = await saber.query("Analyze recent revenue in a sandbox")

The main agent delegates goals through analyze_in_sandbox and receives the answer and artifact references. Each completed analysis automatically publishes its notebook and files to the configured artifact store. The analysis agent keeps its code iterations in a separate conversation.

To continue an analysis, pass the returned session_id to analyze_in_sandbox. close_sandbox retries pending publication before releasing the environment. With the default required-publication policy, a storage failure leaves the session open and returns an error. To retry publication without closing the session or rerunning Python, call publish_sandbox_artifacts.

Capability shutdown also retries publication, but still attempts to release all environments if storage fails. Required publication failures raise a cleanup error.

Pass usage_limits to saber.query() to share a model budget between the main agent and the analysis agent. For non-SQL inputs, set SQLSaberOptions.workspace_input_resolver to your application's attachment resolver.

For provider requirements, GPU options, resource limits, and session lifetime, see the sandbox SDK reference.

Metadata

Release files for sqlsaber-sandbox 0.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 sqlsaber-sandbox 0.7.0
File Size Uploaded
sqlsaber_sandbox-0.7.0.tar.gz 323.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlsaber-sandbox 0.7.0
File Interpreter ABI Platform
sqlsaber_sandbox-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 372.0 kB

Release files / sqlsaber_sandbox-0.7.0.tar.gz

Download URL sqlsaber_sandbox-0.7.0.tar.gz
Size 323.7 kB
Tags Source
SHA-256 checksum
How to use checksums
188bcc71bd2015c24350b8a5e7a88d7e0c50387b37de2979668bb0e96ec49316
BLAKE2b-256 checksum
How to use checksums
b3fdefb5abaefeb63fa5d9873fff3c4875d8a935dde260cea59150dd08de1d53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / sqlsaber_sandbox-0.7.0-py3-none-any.whl

Download URL sqlsaber_sandbox-0.7.0-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b62b9add392301eb7c313682e72b487ee7fea87dae3796724d98c05468c03f59
BLAKE2b-256 checksum
How to use checksums
43a6fefb44c01b0c2e1f5ea049953504a2750dcd51664234e585a1c2a02eb1ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.7.1

2 release files

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

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