Skip to main content

Mosaic Sandbox Python SDK

mosaic-sandbox is the Python SDK and CLI for Mosaic Sandbox, a Firecracker-based runtime for coding agents.

Install (Python 3.9 or newer):

python3 --version   # 3.9 or newer
python3 -m pip install mosaic-sandbox

Authenticate once with the CLI:

mos auth --token msk_live_...
mos whoami

Run the CLI smoke test:

mos doctor
mos run --template node-20 node -v
mos create --template node-20 --ssh
mos ssh <sandbox-id> --print-command

Or run the one-command first-run check:

mos smoke

Python example:

from mosaic_sandbox import Sandbox

sbx = Sandbox.create(
    template="node-20",
    endpoint="https://sandbox.mosaicos.com",
    api_token="msk_live_...",
    enable_ssh=False,
)

try:
    result = sbx.run_command("node -v")
    print(result.stdout)
    print(result.tti_ms)
finally:
    sbx.destroy()

Functions

A function is a name you keep for a one-shot run: a specification — template, command, secrets, network policy, resources, timeout — that lives in your code. Defining one makes no request and creates nothing to deploy or delete. Each invocation creates one isolated microVM, runs the command, and destroys it, so an idle function costs nothing.

from mosaic_sandbox import Function

thumbnail = Function(
    ["python", "-m", "thumbnail"],
    template="python-3.11",
    secrets=["OBJECT_STORE_TOKEN"],
    network={"allow": ["objects.mosaicos.com:443"]},
    timeout_ms=60_000,
)

result = thumbnail.invoke(env={"OBJECT_KEY": "images/input.jpg"})
print(result.stdout, result.sandbox_destroyed)

What the sandbox is stays fixed for every invocation. Only cwd, env, stdin, timeout_ms and idempotency_key may be passed per call; anything else raises rather than being silently ignored, so one call cannot widen another's secrets or egress. Retrying with the same idempotency_key replays the first invocation instead of running a second one.

Work that must outlive one synchronous call belongs in a process or job, and work that needs a URL belongs behind a preview.

LangChain and LlamaIndex tools

Give an agent a sandbox without writing tools for it. Neither framework is a dependency of this SDK; the one you use is imported when you ask for it.

from langchain.agents import create_react_agent
from mosaic_sandbox.integrations.langchain import mosaic_sandbox_tools

agent = create_react_agent(model, mosaic_sandbox_tools(template="python-3.11"))
from llama_index.core.agent import ReActAgent
from mosaic_sandbox.integrations.llamaindex import mosaic_sandbox_tools

agent = ReActAgent.from_tools(mosaic_sandbox_tools(), llm=llm)

The tools — mosaic_run_command, mosaic_run_python, mosaic_run_javascript, mosaic_read_file, mosaic_write_file, mosaic_list_files and mosaic_start_server — share one sandbox, created on the first call rather than when the agent is built. mosaic_start_server returns a public HTTPS preview URL, so "run the dev server and show me" is a single tool call.

Keyword arguments are Sandbox.create's, so snapshot_id= starts the agent in an environment you built earlier. Hold the SandboxToolset yourself if you want to close() it explicitly; close() destroys the sandbox it created but leaves a sandbox you passed in alone, and the toolset is spent either way — a later tool call raises rather than quietly starting a second machine.

Harbor environment provider

Harbor 0.22 and newer can run its trials in Mosaic Sandbox through the first-party provider. Install the optional dependency on Python 3.12 or newer:

python -m pip install 'mosaic-sandbox[harbor]'

Point Harbor at the provider in the trial environment configuration:

[environment]
import_path = "mosaic_sandbox.integrations.harbor:MosaicEnvironment"

Authenticate first with mos login. The provider builds each Docker image or Dockerfile environment once, keyed by its content hash, and starts one Mosaic snapshot replica builds per requested MOSAIC_HARBOR_REPLICAS (default 1) and starts one Mosaic sandbox per trial. Set that variable to an integer from 1 through 16 to spread named snapshot restores across hosts. The optional MOSAIC_HARBOR_TTL_SECONDS variable controls abandoned-trial cleanup and defaults to 3600. Mosaic currently supports Linux single-VM tasks, including no-network and public-IPv4/hostname allowlists; Docker Compose and Windows tasks are out of scope for this provider. A Firecracker guest can run Docker natively, so DinD-style tasks are a plausible follow-up.

Docs: https://sandbox.mosaicos.com/docs/

Release files for mosaic-sandbox 0.14.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 mosaic-sandbox 0.14.0
File Size Uploaded
mosaic_sandbox-0.14.0.tar.gz 260.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mosaic-sandbox 0.14.0
File Interpreter ABI Platform
mosaic_sandbox-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 443.6 kB

Release files / mosaic_sandbox-0.14.0.tar.gz

Download URL mosaic_sandbox-0.14.0.tar.gz
Size 260.2 kB
Tags Source
SHA-256 checksum
How to use checksums
391acddddae47c80e6f83f944f63d0f900ea9930ed2407ba3d756f2a9c73a48d
BLAKE2b-256 checksum
How to use checksums
fcbfe599c5c058fde9f227706213193b361e84c63146787b51929e759b415ed1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release files / mosaic_sandbox-0.14.0-py3-none-any.whl

Download URL mosaic_sandbox-0.14.0-py3-none-any.whl
Size 183.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7ab7743efe58da31cedcc6c5dfd7eef840ea0edb46f2cc361cabc4e18949a13
BLAKE2b-256 checksum
How to use checksums
07a221fc0cde611ccf5b84b258e16866301cc175cf5ac38bb25ab33521036e2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.14.6

2 release files

0.14.5

2 release files

0.14.4

2 release files

This release

0.14.0 This release

2 release files

0.13.2

2 release files

0.12.3

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

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

0.1.0

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