Skip to content

Toolbox

The toolbox is the API inside every sandbox. A daemon in the sandbox runs your commands, processes, terminals and file operations, and your calls reach it only through Daytona’s toolbox proxy, which checks your API key and passes each call into the sandbox. Ports are reached the same way, through preview URLs, and a shell through SSH access you create.

execrunsDaytonasandboxyour WorkerAPI keytoolbox proxychecks the keydaemonexec · files · ptysession devpnpm dev, still runningexecrunsDaytonasandboxyour WorkerAPI keytoolbox proxychecks the keydaemonexec · files · ptysession devpnpm dev, still running
Every toolbox call goes through Daytona's proxy with your key, and the daemon inside the sandbox runs it. A session it started keeps running between calls.

Every sandbox handle carries the toolbox, with Daytona’s own parameters. Get a handle from CreateSandbox or ConnectSandbox.

const result = yield* sandbox.exec("ls -la && cat package.json", { cwd: "/home/daytona/repo" });
// { exitCode: 0, result: "..." }

A non-zero exit comes back in exitCode; it doesn’t fail the Effect. Daytona combines stdout and stderr into result.

An array runs as an argument vector, with no shell to quote for:

yield* sandbox.exec(["git", "commit", "-m", message], { cwd: "/home/daytona/repo" });
const server = yield* sandbox.start(["python3", "-m", "http.server", "8080"], { cwd: "/srv" });
yield* server.output.pipe(
Stream.runForEach((out) => Console.log(out.fd, new TextDecoder().decode(out.data))),
);

start runs the command in its own session and returns while it runs: output streams stdout and stderr, write types into its stdin, wait resolves with its exit code, and kill() ends it (Daytona takes no signal). Closing the scope only detaches.

yield* sandbox.process.createSession({ sessionId: "dev" });
yield* sandbox.process.sessionExecuteCommand({
sessionId: "dev",
command: "pnpm dev --port 3000",
runAsync: true,
});

For a shell whose state carries from command to command, use a session. Sessions keep running between calls. getSessionCommandLogs returns the output so far, with stdout and stderr apart.

yield* sandbox.process
.followSessionCommandLogs({ sessionId: "dev", commandId: started.cmdId })
.pipe(Stream.runForEach((piece) => Console.log(piece.stream, piece.text)));

The stream ends when the command exits. followEntrypointLogs() follows the sandbox’s entrypoint the same way.

const pty = yield* sandbox.pty.open({ cols: 120, rows: 30 });
yield* pty.write("pnpm install && exit\n");
yield* pty.output.pipe(Stream.decodeText(), Stream.runForEach(Console.log));
const { exitCode } = yield* pty.exit;

The connection closes with its scope, and the terminal keeps running until it exits or you kill it. pty.connect(sessionId) attaches to a terminal that already runs. Daytona starts the user’s shell; type the command you want into it.

yield* sandbox.files.makeDir("/home/daytona/out");
yield* sandbox.files.write("/home/daytona/out/report.json", JSON.stringify(report));
const text = yield* sandbox.files.readText("/home/daytona/out/report.json");
const entries = yield* sandbox.files.list("/home/daytona/out");

files also has read (bytes), stat and remove. Daytona’s own file API is on fs, with search and replace:

const hits = yield* sandbox.fs.findInFiles({ path: "/home/daytona/repo/src", pattern: "TODO" });
yield* sandbox.fs.uploadFiles({
files: [
{ path: "/home/daytona/repo/.env", content: "PORT=3000\n" },
{ path: "/home/daytona/repo/logo.png", content: pngBytes },
],
});
const { files, errors } = yield* sandbox.fs.downloadFiles({ paths: ["/home/daytona/out/a.json", "/home/daytona/out/b.json"] });

A path that can’t be read comes back in errors; the rest still download.

yield* sandbox.git.cloneRepository({ url: "https://github.com/alchemy-run/alchemy", path: "/home/daytona/repo" });
const status = yield* sandbox.git.getStatus({ path: "/home/daytona/repo" });
const port = yield* sandbox.getTcpPort(3000);
const res = yield* port.fetch(HttpClientRequest.get("/health"));

getTcpPort gives you a port by its preview URL, and its fetch sends a request there with the token, or proxies one your Worker received. Preview URLs, signed URLs and public are in Network and previews.

const ssh = yield* sandbox.createSshAccess({ expiresInMinutes: 60 });
yield* sandbox.lsp.start({ languageId: "typescript", pathToProject: "/home/daytona/repo" });
const ctx = yield* sandbox.interpreter.createInterpreterContext({ language: "python" });
const run = yield* sandbox.interpreter.executeInterpreterCode({
contextId: ctx.id,
code: "import pandas as pd\nprint(pd.__version__)",
timeout: 30,
});
// { stdout: "2.2.3\n", stderr: "", error: undefined }

A context keeps its variables between runs. An exception the code raises comes back in error; a run past its timeout fails with InterpreterTimeout. streamInterpreterCode streams the same output as it is produced.

yield* sandbox.computerUse.startComputerUse();
const shot = yield* sandbox.computerUse.takeScreenshot();

Computer use needs a snapshot with a desktop. It is billed like any running sandbox.

const logs = yield* sandbox.getSandboxLogs({ from, to });

Point the whole organization’s telemetry at your own backend with OrganizationOtelConfig.