Skip to main content

flaxcloud - Python SDK & CLI for Flax Cloud

Programmatic access to Flax Cloud isolated sandboxes: create them, run commands, move files, preview servers, and wire them into agents/automation.

Install

pip install flaxcloud

Authenticate

Get an API key from the dashboard, then either set an environment variable or log in with the CLI (which stores it in ~/.config/flax/config.json):

export FLAX_API_KEY=flax_live_...
# Optional, for local/self-hosted targets:
export FLAX_BASE_URL=https://flaxcloud.com
# or
flax login

Credentials resolve in this order: explicit api_key, CLI --key, FLAX_API_KEY, then ~/.config/flax/config.json. The base URL is base_url, CLI --url, FLAX_BASE_URL, then https://flaxcloud.com.

SDK

from flaxcloud import FlaxClient

flax = FlaxClient()  # reads FLAX_API_KEY and optional FLAX_BASE_URL

# create_sandbox returns a handle with methods; use it as a context manager to auto-destroy
with flax.create_sandbox(template="python", name="ci-run", memory_mb=512) as sb:
    print(sb.name, sb.id)
    out = sb.run("python3 -c 'print(6*7)'")
    print(out.stdout)          # "42\n"

    sb.upload("/workspace/app.py", "print('hello')\n")
    print(sb.run("python3 app.py").stdout)

    # long-running server + a shareable preview link
    sb.set_startup("python3 -m http.server 8000 --bind 0.0.0.0")
    sb.run_startup()
    print(sb.create_preview_link(8000).url)

Per-sandbox memory is plan-limited: Free 1 GB, Pro 2 GB, Builder 4 GB, Team 8 GB. Requesting more than your plan allows raises FlaxQuotaError with code == "memory_limit":

from flaxcloud import FlaxClient, FlaxQuotaError

flax = FlaxClient()
try:
    flax.create_sandbox(template="python", memory_mb=2048)
except FlaxQuotaError as exc:
    if exc.code == "memory_limit":
        print("Choose a smaller sandbox or upgrade your plan.")
    else:
        raise

Background commands:

sb = flax.create_sandbox(template="node")
job = sb.run("npm install", background=True)
done = sb.wait(job, timeout=600)
print(done.status, done.exit_code)

Environment variables, code execution, git, and filesystem helpers:

sb = flax.create_sandbox(template="python", env={"API_BASE": "https://example.com"})
sb.run("printenv TOKEN", env={"TOKEN": "secret"})        # per-command override
sb.set_env({"API_BASE": "https://new.example.com"})       # future process defaults
sb.code_run("print(6*7)", language="python")             # also node/bash/ruby
sb.git.clone("https://github.com/me/repo.git", "/workspace/repo")
sb.mkdir("/workspace/out"); sb.find("/workspace", name="*.py")

Environment payloads are encrypted at rest. Flax also places HOME and XDG state under the durable workspace automatically, so normal tool state survives stop/resume.

Stateful sessions - working directory and exported env persist across commands:

with sb.create_session() as s:        # auto-deletes on exit
    s.run("cd /workspace && export TOKEN=abc")
    print(s.run("pwd").stdout)         # /workspace
    print(s.run("echo $TOKEN").stdout) # abc

Streaming - live combined stdout/stderr as the command runs:

stream = sb.run_stream("for i in 1 2 3; do echo $i; sleep 1; done")
for chunk in stream:
    print(chunk, end="", flush=True)
print("exit:", stream.exit_code)

Custom images - register any public registry image, then create sandboxes from it:

tpl = flax.create_template("my-python", image="python:3.12-slim")  # waits until ready
sb = flax.create_sandbox(template="my-python")
print(sb.run("python3 --version").stdout)

You can also build a custom image from a Dockerfile (flax.create_template(..., dockerfile=...), streamed with flax.build_logs(id)), or describe it declaratively with FlaxImage and let the SDK generate the Dockerfile for you. The declarative builder uses the same Dockerfile build flow under the hood, so build status, logs, and wait behave identically:

from flaxcloud import FlaxImage

image = (
    FlaxImage.python("3.12")
    .apt_install(["git", "ffmpeg"])
    .pip_install(["requests", "beautifulsoup4"])
    .env({"PYTHONUNBUFFERED": "1"})
    .workdir("/workspace")
)

# Inspect the generated Dockerfile if you want:
print(image.to_dockerfile())

template = flax.create_template_from_image_definition("scraper-agent", image, wait=True)
sb = flax.create_sandbox(template="scraper-agent")

FlaxImage constructors: base(image), python(version), node(version), debian_slim(). Steps (chainable): apt_install, pip_install, npm_install, run, env, workdir, copy_file, copy_dir. Each package/argument is single-quoted and validated, so version specifiers like "requests>=2,<3" are safe; use .run(...) for anything custom. Note: copy_file/copy_dir need a local build context, which the hosted builder does not accept yet, so templates that use them can't be built remotely for now (use .run(...) to fetch files instead).

Filesystem snapshots - capture a prepared sandbox and create fresh sandboxes from it:

sb = flax.create_sandbox(template="python", env={"READY": "1"})
sb.upload("/workspace/app.py", "print('ready')\n")
snap = sb.create_snapshot("agent-base")
sb.destroy()

restored = flax.create_sandbox(snapshot_id=snap.id)
print(restored.read_text("/workspace/app.py"))
flax.delete_snapshot(snap.id)

Snapshots preserve /workspace and sandbox configuration, not running processes or RAM.

Fork a sandbox - create an independent copy of its filesystem and configuration:

base = flax.create_sandbox(template="python", env={"CASE": "base"})
base.upload("/workspace/input.txt", "baseline")

fork = base.fork(metadata={"branch": "eval-a"})
fork.upload("/workspace/input.txt", "changed in fork")

print(base.read_text("/workspace/input.txt"))  # baseline
print(fork.read_text("/workspace/input.txt"))  # changed in fork

Forks copy /workspace and sandbox configuration, not running processes, RAM, terminal sessions, preview links, or command history.

Browser-capable sandboxes:

browser = flax.create_sandbox(capabilities=["browser"])
browser.browser.start()
cdp_url = browser.browser.get_cdp_url()
shot = browser.browser.screenshot_bytes()

Browser sandboxes persist browser artifacts under /workspace/.flax/browser/{profile,screenshots,downloads,traces}. Browser automation is CDP-first: connect Playwright, Puppeteer, browser-use, Stagehand, or your own CDP client to the short-lived authenticated URL from get_cdp_url().

Async client:

import asyncio
from flaxcloud import AsyncFlaxClient

async def main():
    async with AsyncFlaxClient() as flax:
        async with await flax.create_sandbox(template="python") as sb:
            print((await sb.run("echo hi")).stdout)

asyncio.run(main())

Errors are typed (FlaxAuthError, FlaxNotFoundError, FlaxQuotaError, …), all subclasses of FlaxError. The client retries transient failures, sends a versioned User-Agent, and ships type hints (py.typed).

CLI

flax login
flax sandbox create --browser
flax browser start sbx_browser
flax browser cdp-url sbx_browser
flax browser screenshot sbx_browser -o shot.png
flax sandbox create --template python --startup "python3 -m http.server 8000 --bind 0.0.0.0"
flax sandbox ls
flax run sbx_abc123 "python3 -c 'print(6*7)'"
flax run sbx_abc123 "make build" --stream         # stream output live
flax session create sbx_abc123                     # cwd/env persist across exec
flax session exec ses_xyz "cd src && export E=1"
flax cp ./app.py sbx_abc123:/workspace/app.py
flax ls sbx_abc123 /workspace
flax snapshot create sbx_abc123 agent-base
flax snapshot ls
flax snapshot rm snap_abc123
flax preview sbx_abc123 8000
flax sandbox rm sbx_abc123

flax --help lists every command.

Metadata

Release files for flaxcloud 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flaxcloud 0.5.2
File Size Uploaded Provenance Actions
flaxcloud-0.5.2.tar.gz 28.7 kB Without provenance Details for flaxcloud-0.5.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flaxcloud 0.5.2
File Interpreter ABI Platform Actions
flaxcloud-0.5.2-py3-none-any.whl Python 3 none any Details for flaxcloud-0.5.2-py3-none-any.whl

Total release size: 62.9 kB

Release files / flaxcloud-0.5.2.tar.gz

Download URL flaxcloud-0.5.2.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
68500966325add583bffc5695f102e4aacde62bf8158e86f5b68d1e47f6533b8
BLAKE2b-256 checksum
How to use checksums
f8cbd5a152a99b7a33e6fff55448275a0a28b4cd98182e46ff9e3a813d5ea4ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / flaxcloud-0.5.2-py3-none-any.whl

Download URL flaxcloud-0.5.2-py3-none-any.whl
Size 34.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54266ea739d6eafd29cbe7607a42f4a65f3dfe99e2548e960c17419e2fe0da93
BLAKE2b-256 checksum
How to use checksums
9df876497a075cf71e07271bef8f5abf6dd1fbbf12748bbf8e6eee971d7537b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for flaxcloud 0.5.2

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.

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