Commands and files
The E2B SDK's sandbox.commands.* and sandbox.files.* calls work on Kibotos sandboxes as they do on E2B. This page covers the supported process and file endpoints, which user a request runs as, how paths resolve, and how process streams and directory watches behave.
Supported endpoints
The process and file endpoints use the same wire format as E2B's envd: the Connect, gRPC, and gRPC-Web protocols, JSON and binary encodings, and gzip compression negotiation.
| Area | Endpoints | In the SDK |
|---|---|---|
| Processes and PTY | /process.Process/{Start,Connect,SendInput,CloseStdin,SendSignal,Update}, all POST | sandbox.commands.* |
| Files | /filesystem.Filesystem/{Stat,MakeDir,Move,ListDir,Remove,WatchDir} (POST), GET /files, POST /files | sandbox.files.* |
| Health check | GET /health | — |
PTYs and ordinary commands both start with Start.
Running commands
The following example runs a command as root in /tmp and prints its output:
const result = await sandbox.commands.run('id -un && pwd', { user: 'root', cwd: '/tmp' });
console.log(result.stdout);Without user and cwd, the command runs as the Template's user in that user's home directory. See User and working directory.
If the connection between the gateway and the node drops while the command runs, the output keeps arriving on the same stream. See Process streams.
User and working directory
Every process and file request runs as a user in the guest. You choose it with the SDK's user option, and process requests also take a cwd.
Choosing the user
- Without a user, the user the Template declares is used.
rootmeans root.- The gateway does not validate user names. The node rejects a user name the Template does not declare with
invalid_argument, and the SDK receives that error unchanged.
Working directory and relative paths
- Without a
cwd, the process starts in the home directory of its user. - Relative file paths and
cwdvalues resolve against the home directory of the user.~and~/…also refer to that directory, as in E2B. ~namerefers to another user's home and returnsinvalid_argument.- If the Workspace's guest is older than
v0.3.0, only absolute paths are accepted, and relative paths return 400. Restart the Workspace to enable relative paths.
The following example writes a file with a relative path and reads it back. If the Template declares the user user, both calls use /home/user/notes.txt:
await sandbox.files.write('notes.txt', 'hello');
console.log(await sandbox.files.read('notes.txt'));How the user is sent
The envd protocol passes the user that runs a request through HTTP basic auth:
- When you specify
user, the SDK sendsAuthorization: Basic base64(username + ":"). - The gateway passes the user name unchanged to the native API: the
userfield ofStartand file system requests, and theuserquery parameter of/v1/files. GET /filesandPOST /filesalso accept theusernamequery parameter of the envd protocol. When both are present, basic auth wins.X-Access-Tokenremains the authentication credential. Basic auth expresses identity only.
Process streams
When the process stream between the gateway and the node drops, the gateway resumes it automatically. The SDK keeps receiving the same stream, with no lost or duplicated output. The gateway retries for at most 30 seconds.
The sandbox keeps only a bounded amount of recent output for each process; for the limits, see Resuming process streams. If the disconnect lasts long enough for the output to exceed them, the lost part cannot be recovered. The stream then ends with data_loss, instead of handing output with a gap to the SDK as if it were continuous.
Watching directories
files.watchDir (WatchDir) watches a single directory, without its subdirectories:
- A watch ends when the directory is deleted or moved away, the sandbox is paused, or events cannot be delivered in time.
onExitreceives the corresponding error. For the reasons a watch ends, see Tracking a directory. allowNetworkMountsis ignored.
Two forms of watching are not available, and both are listed in Not supported:
recursive: truereturnsunimplemented.CreateWatcher,GetWatcherEvents, andRemoveWatcherreturnunimplemented. They require the gateway to keep watch state across requests, and the gateway keeps no state.
Notes
- On Kibotos, each request message to the process and file endpoints is limited to 4 MiB, measured after decompression for compressed messages. Larger messages return
resource_exhaustedand are not forwarded to the sandbox. E2B has no such limit, so split data larger than about 3 MiB across severalsendStdincalls. files.writeuploads at most 1 GiB per file; a larger upload returns 413 (resource_exhausted). Reads have no size limit:files.readreads a file of any size, and the gateway fails the read if the file changes while it is being read. Beforev0.3.0, the gateway returns 413 for a file larger than 1 GiB.
Next steps
- Sandboxes and lifecycle: create, pause, resume, and expire sandboxes.
- Volumes: mount a standalone Volume in a sandbox.
- Commands and terminals: the native process API behind these endpoints.
- Files: the native file API, its limits, and its errors.
Sandboxes and lifecycle
With the E2B SDK you create, pause, resume, extend, and kill sandboxes on Kibotos with the same calls as on E2B. This page covers how each lifecycle call behaves on Kibotos, what resources a new sandbox gets, how expiration and Idempotency-Key retries work, and what queries return.
Network
Control a sandbox's outbound access with the E2B SDK's allowInternetAccess and network create options, and change it later with sandbox.updateNetwork(). The gateway turns these settings into a Kibotos network policy, and can send the sandbox's outbound TCP through your own SOCKS5 proxy.