Client¶
The entry point of the client: connect() opens a
Client on the socket of the daemon, and
Client.create() returns a
Creation, awaited or used as an async context
manager.
fastsandbox.connect
async
¶
connect(socket: str | PathLike[str] | None = None, *, timeout: float | None = None, long_operation_timeout: float | None = None, version_policy: VersionPolicy = 'strict') -> Client
Connects to the daemon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
socket
|
str | PathLike[str] | None
|
The socket path; |
None
|
timeout
|
float | None
|
Deadline of ordinary requests, in seconds. |
None
|
long_operation_timeout
|
float | None
|
Deadline of long operations (creation, image pulls), in seconds. |
None
|
version_policy
|
VersionPolicy
|
What to do with an API version this release was not
audited on: |
'strict'
|
Raises:
| Type | Description |
|---|---|
DaemonUnavailableError
|
When the daemon cannot be reached. |
UnsupportedVersionError
|
When its API version is not supported and
|
fastsandbox.Client
¶
Client(native: Client, *, kits: KitCache | None = None)
A connection to the daemon: the entry point of every other handle.
It can be used as an async context manager; closing it releases nothing, connections are opened per request.
kits
property
¶
kits: KitCache
The kit cache create takes packages from: the one of the process by default.
sandbox
¶
The handle of the sandbox name; nothing is checked until it is used.
package
async
¶
package(kit: Kit | KitPackage | str) -> KitPackage
The package of kit.
A kit is forged without the sbx CLI on first use, or compiled by it for a cache
given the CLI (see KitCache); a package is returned as is.
create
¶
create(name: str | None = None, *, kit: Kit | KitPackage | str | None = 'shell', request: CreateRequest | None = None, workspace: str | PathLike[str] | None = None, clone: bool = False, workspaces: Sequence[Workspace] = (), env: Mapping[str, str] | None = None, ports: Sequence[PortBinding] = (), cpus: int | None = None, memory: str | None = None, template: str | None = None, pull_policy: PullPolicy | None = None) -> Creation
Creates a sandbox.
Await the result to get the sandbox, which stays until deleted; or use it as an async context manager, which deletes the sandbox on exit.
Example
async with client.create(kit="shell") as sandbox: ... async with sandbox.running(): ... await sandbox.exec("uname -a")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The sandbox name; a unique one by default. |
None
|
kit
|
Kit | KitPackage | str | None
|
The kit, its package made on first use by the kit cache of the
client ( |
'shell'
|
request
|
CreateRequest | None
|
A full creation request; the other arguments adjust it. |
None
|
workspace
|
str | PathLike[str] | None
|
A host directory mounted as workspace, at its own path. |
None
|
clone
|
bool
|
The agent works on a private clone of the Git repository of
|
False
|
workspaces
|
Sequence[Workspace]
|
Further directories or files to mount. |
()
|
env
|
Mapping[str, str] | None
|
Environment variables of the sandbox. |
None
|
ports
|
Sequence[PortBinding]
|
Ports published from the start. |
()
|
cpus
|
int | None
|
Number of virtual CPUs. |
None
|
memory
|
str | None
|
Memory limit in |
None
|
template
|
str | None
|
Image to start from, e.g. one saved with |
None
|
pull_policy
|
PullPolicy | None
|
When to pull kit images. |
None
|
fastsandbox.Creation
¶
Creation(client: Client, name: str, kit: Kit | KitPackage | str | None, request: CreateRequest | None, overrides: dict[str, Any], workspaces: list[Workspace], env: dict[str, str], ports: list[PortBinding])
A sandbox being created.
Await it, or use it as an async context manager that deletes the sandbox on exit, by its identifier: a sandbox another program created since under the same name stays.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The name of the sandbox. |
|
created |
Created | None
|
What the daemon answered once the sandbox exists (its identifier, the
credentials it withholds), |
fastsandbox.ProxiedKey
¶
An API key the proxy of a sandbox writes in place of its placeholder.
The key is written in the requests to its hosts only, whatever the network rules of the sandbox allow; the agent sends the content of its variable in a header, as an API client does with a key. Its value is never read back.
The key value, read by the agent from the variable env, for hosts.
Its placeholder is generated, under the prefix the crate gives every placeholder.
value may be a pydantic.SecretStr, passed on without being exposed in between.
Raises:
| Type | Description |
|---|---|
InvalidRequestError
|
For a variable that is not one, or no host. |
for_service
classmethod
¶
for_service(package: KitPackage, service: str, env: str, value: str | SecretStr) -> ProxiedKey
The key of the service service, for the hosts the kits of package inject it into.
For anthropic and the claude kit, api.anthropic.com.
Raises:
| Type | Description |
|---|---|
InvalidRequestError
|
When no kit of the package declares the service, or for a variable that is not one. |
fastsandbox.SOCKET_ENV
module-attribute
¶
SOCKET_ENV: str = _native.SOCKET_ENV
The environment variable that names the socket of the daemon, DOCKER_SANDBOXES_API.
connect and default_socket_path read it first, before the state directory of sbx.
fastsandbox.SUPPORTED_API
module-attribute
¶
The API versions of the daemon this release supports: the minimum, included, and the maximum, excluded.
("0.52.0", "0.53.0") is >=0.52.0, <0.53.0: connect refuses a daemon outside it, unless its
version_policy says otherwise.