Skip to main content

Shark SDK for Python

Persistent Spaces for AI agents: every command runs in a fresh microVM, the files stay. Python 3.9+, standard library only (no dependencies).

pip install sharkmagic

Use

from sharkmagic import Shark

shark = Shark()                                    # reads SHARK_API_KEY
space = shark.spaces.create(name="quickstart")

r = space.run("echo hello > hello.txt && cat hello.txt")
print(r.exit, r.stdout.strip())                    # 0 hello

print(space.files.read_text("hello.txt"))          # served from the committed tree, no VM

for fork in space.fork(count=2):                   # copies of the Space at the same commit, nothing copied
    print(fork.id, fork.run("cat hello.txt").stdout.strip())

print(space.run("exit 7").exit)                    # a failing command is a result, not an exception

Also: space.run(cmd, cwd=..., env=..., timeout=..., check=True), space.stream(cmd) (live events), space.start(cmd) (an Op at once), space.files.write(...), space.files.upload_dir(...), space.hibernate(), space.delete(). Async: AsyncShark.

SDK Spaces: nothing of your account unless asked

Spaces made by the SDK are sdk Spaces (space.profile): your account's secrets, GitHub connection, background jobs and the in-Space CLI credential do not reach them unless the Space asks (docs: api.md#sdk-spaces-and-devbox-spaces-profile).

sp = shark.spaces.create(labels={"customer": "acme"}, egress="coding",      # "deny" | "coding" | "open" | a policy
                         account_secrets=["OPENAI_API_KEY"],                 # "all" | "none" (default) | names
                         github=False, git={"name": "Acme Bot", "email": "bot@acme.test"},
                         keep_background=False, keep_awake=False, space_cli=False)   # space_cli=["spaces:read"]: scopes
sp.update(account_secrets=None)                       # None: back to the profile's default
sp.run("python srv.py &", background=True)            # this command's leftovers stay as a job
forks = sp.fork(count=3, account_secrets="none")      # forks keep the source's choices unless overridden
[s.id for s in shark.spaces.list(label="customer:acme")]

sp.secrets.set("STRIPE_KEY", key, hosts=["api.stripe.com"], in_=["bearer"])   # inject (the value never enters the VM)
sp.secrets.set("GITHUB_TOKEN", tok, preset="github", allow_egress=True)         # bring your own GitHub token
sp.secrets.set("DB_URL", url, exec=True); sp.run("…", secrets=["DB_URL"])      # exec: in that command's env
sp.secrets.rotate("STRIPE_KEY", new_key); sp.secrets.edit("STRIPE_KEY", hosts=[…]); sp.secrets.remove("DB_URL")
sp.secrets.reference("OPENAI_API_KEY")                # use one account secret here
shark.secrets.set("OPENAI_API_KEY", key, preset="openai", apply="ref")   # account secrets; shark.secrets.presets()
shark.space_defaults.set(account_secrets="none")      # the account's default for unset fields

profile="devbox" makes a Space as shark create / shark code do (account secrets, GitHub, background jobs).

Your own GitHub App (control-plane mode): shark.github_app.register(app_id, pem) once, then shark.github_app.link(space, installation_id, repos=["site"]) stores that installation's token as the Space's GITHUB_TOKEN (its node keeps it fresh); status(), remove().

Credentials

  • SHARK_API_KEY: an API key from the Shark console (shk_live_…). Keep it in the environment, never in code.
  • The SDK exchanges the key at the control plane (https://api.sharkmagic.si, or SHARK_CP) for short-lived node credentials and sends each call to the node that holds the Space. The key itself never reaches a node.
  • Self-hosted node: Shark(base_url=..., api_key=...) or SHARK_API (the node's own key).

Errors

Every API error is a sharkmagic.SharkError subclass with a stable code (credits_exhausted, not_found, quota_exceeded, …). Retries keep the same op_id, so a command never runs twice.

Framework integrations

Optional extras: sharkmagic[langchain], [langgraph], [smolagents], [prefect] (sharkmagic.integrations.*).

Docs

https://sharkmagic.si — quickstart, API reference, error codes and limits are linked from there.

Metadata

Release files for sharkmagic 0.1.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 sharkmagic 0.1.0
File Size Uploaded Provenance Actions
sharkmagic-0.1.0.tar.gz 61.3 kB Without provenance Details for sharkmagic-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 109.4 kB

Release files / sharkmagic-0.1.0.tar.gz

Download URL sharkmagic-0.1.0.tar.gz
Size 61.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f5a8d7697a300b6253678a002e9983b4ed94068a1d90881a1b6984bb863d85ff
BLAKE2b-256 checksum
How to use checksums
e316e1d95854c01cda30a91414ddf5ad5e52c159d769918f92ae3c92b0239c48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / sharkmagic-0.1.0-py3-none-any.whl

Download URL sharkmagic-0.1.0-py3-none-any.whl
Size 48.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e9455550a2be7179fd2ca89f49c2db2a843061ea25d71396619ca852fce3bd9
BLAKE2b-256 checksum
How to use checksums
0d11b6488df20efa41511092f1bba16c4005d2d69fa74c2e275ff8c5af0c8245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for sharkmagic 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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