Each Agent runs inside an isolated OpenSandbox container with its own private /workspace/project workspace. Inside the sandbox, the AnySwarm worker supervisor launches your chosen executor (Pi, Codex, or an image-installed custom adapter), verifies file transfers, and exports the Agent’s session and artifacts once execution has cleanly stopped.
1. Local setup
anyswarm setup --mode local --backend pi
anyswarm doctor --smoke
Setup uses the selected host npm installation and the current SDK package to prepare a local Worker. It verifies the Worker identity and managed OpenSandbox services, then saves the connection after a controlled smoke test. The Worker handshake protocol is anyswarm-core-v2.
2. Connect to an existing service
export OPEN_SANDBOX_API_KEY='<operator-provided-key>'
anyswarm setup --mode existing \
--endpoint https://sandbox.example.net \
--public-url https://runtime.example.net/anyswarm
anyswarm doctor --mode existing --smoke
Existing mode verifies your management API key and saves the connection in owner-only user config without launching a container. Running anyswarm doctor --mode existing --smoke then creates and deletes a temporary sandbox to verify host-to-worker access, Runtime callbacks, file export, and cleanup.
In remote mode, the OpenSandbox operator supplies the Worker image, which you select with ANYSWARM_WORKER_IMAGE; your host machine running anyswarm only needs Node.js and network access. Protect credentials with TLS (HTTPS) or a trusted private network.
3. Configure createSandbox() in the SDK
import { createSandbox } from '@anyswarm/core';
// Reuse the connection saved by `anyswarm setup` (recommended)
const sandbox = createSandbox();
// Or specify a remote endpoint and resource limits explicitly
const remote = createSandbox({
endpoint: 'https://sandbox.example.net',
apiKey: process.env.OPEN_SANDBOX_API_KEY,
resourceLimits: { cpu: '2', memory: '2Gi' },
timeoutSeconds: 3600,
});
Configuration precedence is: explicit SDK/CLI options → environment variables → saved user config (owner-only permissions) → local defaults. createSandbox() validates and snapshots settings without launching containers; allocation starts only when you call runtime.spawn().
When sandboxes run on a remote host or behind a reverse proxy, pass connection: { publicUrl: 'https://runtime.example.net/anyswarm' } to createRuntime() to advertise a single reachable callback URL (reverse-proxy path prefixes are preserved; use bindHost and bindPort only when you need custom listener binding). anyswarm doctor --mode existing reports the active callback origin, and anyswarm doctor --mode existing --smoke points to the callback address, port, and proxy routes if sandboxes cannot call back. Configure OpenSandbox to publish reachable container endpoints and required headers.
4. Resources and compatibility notes
| Setting or capability | Current behavior |
|---|---|
| CPU & memory limits | Passed via the official OpenSandbox SDK and verified against actual guest cgroup limits at startup. |
timeoutSeconds |
Initial sandbox lifetime (default: 3,600 seconds). An active Runtime automatically renews leases for running, idle, and retained sandboxes. |
| Required export failure | Retains the sandbox and capacity slot with its actual expiresAt. close() tries to confirm at least a 5-minute troubleshooting window (reporting retain-at-risk if unconfirmed). Fix the issue and retry stop() or close() to finish cleanup. |
File budgets (maxBytes / maxEntries) |
Configured per stage (import, snapshot, replace, export, session) via createRuntime({ filePolicy }). |
lifecycleBaseUrl |
Deprecated compatibility alias for endpoint (conflicting values are rejected); planned for removal in the next breaking release. |
isolation.network: 'api' |
Deprecated redundant option (OpenSandbox API is now the sole built-in mode); planned for removal in the next breaking release. |
Dual callback URLs & {port} templates |
Migrate to a single connection.publicUrl (with optional fixed bindPort). Matching legacy URLs remain temporarily accepted until the next breaking release. |
local-docker & exact byte/inode quotas |
Removed and rejected before allocation with migration guidance. If you require strict byte/inode quotas, supply a trusted custom SandboxProvider. |
| Live shared workspace | Rejected before creation by the built-in OpenSandbox provider. Exchange files via runtime.files or a shared Service, or plug in a custom provider with verified shared access. |
endpointHost |
Rejected. Fix advertised endpoint URLs directly in your OpenSandbox server configuration. |
useServerProxy |
Legacy compatibility switch for existing proxy-routed deployments (tracks upstream maintenance status). New deployments should publish directly reachable endpoints. |
Packet-level egress allowlists (egressMode: 'dns+nft')
Set egressMode: 'dns+nft' when your OpenSandbox deployment has administrator-configured packet filtering enabled. anyswarm compiles each Profile’s IPv4 HTTP(S) network.allow origins — plus the Runtime callback target — into exact IP and TCP port rules, failing fast before allocation if the deployment does not advertise dns+nft support. Before starting an Agent, Runtime verifies that the egress sidecar reports dns+nft mode with the requested allowlist. Test blocked destinations directly in your deployment, and keep in mind that cluster-wide deny policies still take precedence.
5. Worker images and custom Providers
workerImageFor(executor)selects a local Worker for that executor. An explicit version pins the expected version.DEFAULT_WORKER_IMAGEuses the Runtime’s selected local executor.- Extend a prepared local Worker by using the reported
worker.referenceas the base image. SetProfile.imagewhen a role needs extra toolchains (such as Lean 4 or custom compilers), keeping the SDK version,anyswarm-core-v2protocol, and executor version aligned. - To integrate another sandbox platform, pass
createSandbox({ provider, timeoutSeconds })implementing the publicSandboxProviderinterface. Deployment recipes and pinned versions live in the Deployment Guide.
6. Kubernetes deployment
In Kubernetes mode, a single Runtime connects to one OpenSandbox cluster endpoint with a stable callback URL, while Kubernetes schedules Sandbox pods across prepared worker nodes. Durable Runs support same-host, same-boot recovery under an exclusive writer lock (automatic cross-node failover is not yet supported).
See Durable recovery and Kubernetes and the OpenSandbox Kubernetes deployment guide for pinned manifests, recovery boundaries, and capacity benchmarks.
Next: hand your Sandbox configuration to Runtime to stream events, sync files, update config live, and shut down or recover cleanly.