Official JavaScript/TypeScript SDK for Pocketenv.
npm install @pocketenv/sdk
# or
bun add @pocketenv/sdkThe SDK resolves your API token from the first available source:
- Passed explicitly to
Sandbox.configure({ token })orSandbox.create({ token }) POCKETENV_TOKENenvironment variable~/.pocketenv/token.json— a JSON file with the shape{ "token": "tok_..." }
This means Sandbox.configure() is optional if you have a token file or environment variable set.
import { Sandbox } from "@pocketenv/sdk";
// No configuration needed if ~/.pocketenv/token.json or POCKETENV_TOKEN is set
const sandbox = await Sandbox.create({ base: "openclaw" });
// Run a command
const result = await sandbox.sh`echo hello`;
console.log(result.stdout); // "hello\n"
// With interpolation
const dir = "/home/user";
const files = await sandbox.sh`ls -la ${dir}`;
// Stop and clean up
await sandbox.stop();
await sandbox.delete();Optionally set a global API token (and optional base URL) used by all subsequent calls. If omitted, the SDK falls back to POCKETENV_TOKEN or ~/.pocketenv/token.json.
Create a new sandbox. Pass token inline to skip configure().
const sandbox = await Sandbox.create({
base: "openclaw",
name: "my-sandbox",
token: "tok_...",
});Fluent builder for creating sandboxes — useful when setting many options, especially multiple envs or secrets.
const sandbox = await Sandbox.builder("openclaw")
.name("my-sandbox")
.vcpus(4)
.memory(8192)
.env("NODE_ENV", "production")
.env("PORT", "3000")
.secret("API_KEY", process.env.API_KEY!)
.keepAlive()
.create();Available builder methods: name, description, provider, topics, repo, vcpus, memory, disk, readme, env, secret, keepAlive, token, baseUrl.
Fetch an existing sandbox by ID.
List all sandboxes.
| Method | Description |
|---|---|
sandbox.start({ repo?, keepAlive? }) |
Start the sandbox |
sandbox.stop() |
Stop the sandbox |
sandbox.delete() |
Delete the sandbox |
sandbox.exec(command) |
Run a raw command |
sandbox.sh\command`` |
Run a shell command via /bin/sh -c (tagged template or string) |
sandbox.expose(port, description?) |
Expose a port publicly |
sandbox.unexpose(port) |
Remove a port exposure |
sandbox.vscode() |
Expose VS Code; returns the preview URL |
sandbox.getSshKeys() |
Get the sandbox SSH key pair |
sandbox.putSshKey(publicKey, privateKey) |
Set an SSH key pair (private key is encrypted automatically) |
sandbox.createBackup(directory, description?, ttl?) |
Create a backup of a sandbox directory |
sandbox.listBackups() |
List all backups for the sandbox |
Sandbox.restoreBackup(backupId) (static) |
Restore a sandbox from a backup |
sandbox.file—write,list,get,update,deletesandbox.env—put,list,get,update,deletesandbox.secret—put,list,get,update,deletesandbox.volume—create,list,get,update,deletesandbox.ports—listsandbox.service—add,list,start,stop,restart,update,deletesandbox.tailscale—getAuthKey,setAuthKeysandbox.backup—create(directory, description?, ttl?),list(),restore(backupId)
bun install
bun test # run tests
bun run build # compile to dist/MIT