Skip to main content

Python SDK and CLI for Flax Cloud — isolated cloud sandboxes.

Project description

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_...
# or
flax login

SDK

from flaxcloud import FlaxClient

flax = FlaxClient()  # reads FLAX_API_KEY

# create_sandbox returns a handle with methods; use it as a context manager to auto-destroy
with flax.create_sandbox(template="python") as sb:
    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)

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.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")

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)

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 --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 preview sbx_abc123 8000
flax sandbox rm sbx_abc123

flax --help lists every command.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flaxcloud-0.3.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flaxcloud-0.3.0-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file flaxcloud-0.3.0.tar.gz.

File metadata

  • Download URL: flaxcloud-0.3.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for flaxcloud-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ab4dbe4fd5026a6b890c71f1c1fb2ad4d32e6cd6347305689c9243aa37240782
MD5 01a6ebe4aec05a8dedd8aae84aec2483
BLAKE2b-256 50f63137f13f5b055232958af8be9aa29e1e8dfa51fa3947c6f561fcfae89865

See more details on using hashes here.

File details

Details for the file flaxcloud-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flaxcloud-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for flaxcloud-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cfe42d9b5997949d4de17c06d193518accbf6661cef3f98423939f4bcac5b626
MD5 8fdf206e6cdd4ebeec503e701e74cc81
BLAKE2b-256 4748e059139ffab75be0ed76a2f7c13436a7088b6218b28e02422a659c9985c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page