Install
@capsule-run/vpod/browser instead. The package root
resolves by export condition, which some bundlers get wrong for client code.
Overview
Everything is async, because loading the engine and fetching a snapshot are.
Persistent sessions
All calls share one running sandbox, so state carries across them. Declaring it withawait using closes it when the scope ends:
await using, call await sandbox.close()
yourself.
Shell commands and Python code share one filesystem:
Return values
sandbox.commands.run(cmd)
sandbox.code.run(source)
For commands that run long enough to bound, watch, or feed input to — timeouts,
interrupts,
AbortSignal, streaming output, and stdin — see
Process I/O.Sandbox.create() options
snapshot
A registry name, or a snapshot you built yourself:
The first
Sandbox.create() downloads the snapshot and caches it, on disk in Node
and in origin-private storage in a browser. Later runs use the cache. See
Snapshots.network
The guest’s network is on by default wherever it can be. Pass false to run
fully offline, or true to fail loudly instead of silently starting without it:
sandbox.network reports what the guest can actually reach:
mounts
Host directories the guest can see, as a guest path per host path. Read only
unless you append :rw:
:rw mount lands on the
host, and it sees host edits as they happen.
Mounts need a host filesystem, so they work under Node and throw in a browser.
Everything else in this SDK runs in both.
env
Environment variables the guest starts with. They reach commands, anything those
commands spawn, and code.run.
$, and backticks in a value are never
interpreted by the shell. Names must be plain identifiers.
secrets
A credential the sandbox can use but never read. The guest is given a
stand-in through its environment; the value itself goes only to the network
gateway, which swaps it back in on the way out, and only for a host you named.
Set
placeholder yourself when a client library checks the shape of a key:
trace
Records what the sandbox actually did, which programs ran, which files changed
and where it connected. Off unless you ask for it, and chosen at creation:
engine
Some private snapshots come with their own engine, which runs the tools
installed in them faster. With the default "auto", the sandbox uses that engine
when it is already cached, and otherwise starts on the engine bundled with the
SDK while the snapshot’s engine downloads for next time. See
Private snapshots.
Pass "default" to always use the bundled engine, for instance on a page that
should not download anything extra:
sandbox.tier says which engine it got: "image" for the snapshot’s own,
"aot" or "base" for the bundled one.
Differences from the Python SDK
Three things differ, and all three surprise people who move between the two:
- The default snapshot is
vsnap-base:latesthere andalpinein Python. sandbox.suspend()returns the delta bytes, not an instance id. Browsers have nowhere to put a file, so where the state goes is your decision. See Suspend & resume.- There is no
mountsoption. Mounting a host directory has no meaning in a browser tab, so the TypeScript SDK does not offer it anywhere.