Shaf Lab

Code sandboxes

Restricted environments where untrusted or agent-written code can run safely.

A code sandbox is a restricted environment where untrusted or agent-written code can run without taking over the host. It might be a container with tight privileges, a micro-VM, or a language-level isolate. The point is to let the agent compile, test, or try a script while you still control the network, the filesystem, and the lifetime of the process.

Use a sandbox when the code did not come from a review you trust, or when you want to run many agent jobs in parallel without them seeing each other's files. A personal laptop with the secrets already loaded is a poor sandbox, even if the agent is 'just running tests.'

The usual controls are: a fresh filesystem, no credentials except the ones you inject, limited outbound network, a CPU and time cap, and a clean shutdown. If a job needs the network, allow only the hosts it should call. Snapshotting the workspace after a run is useful when you want to inspect what the agent changed.

Sandboxes add friction, so apply them where the risk is real. A throwaway function test is a good candidate. A one-line typo fix in a repo you are already watching might not need a new VM.

Browser-based virtual machines

Whole computers, usually Linux, that run inside a browser tab using WebAssembly, on the visitor's own device.

A browser-based virtual machine is a whole computer, usually Linux, running inside a browser tab. The machine is built from WebAssembly, so it runs inside the same sandbox as any web page. It can't see the visitor's files, and closing the tab ends it. Nothing runs on a server, which makes it a private, disposable computer with no per-user hosting cost.

There are four ways to build one. The oldest emulates a whole PC, BIOS, CPU and devices included. It is faithful but slow. The second translates the guest CPU's instructions to WebAssembly on the fly and answers Linux system calls with a custom runtime. The third skips Linux entirely: programs are recompiled to WebAssembly and run on a small Linux-like kernel written for the web. The newest compiles the real Linux kernel itself to WebAssembly and emulates only the user programs, which gets kernel work close to native speed.

Every approach runs into the same browser limits. Fast threads need a cross-origin isolated page. A page can't open raw network sockets, so traffic goes through fetch() or a WebSocket relay. Memory is capped by the tab. Disks are usually a read-only image streamed on demand, with the user's changes saved in browser storage.

The common uses are teaching (a real shell for every learner with nothing to install), sandboxes where coding agents can run bash safely, reproducible demos and bug reports, and preserving old software. Heavy builds, GPU work and long-running jobs still belong on servers.

External sandboxes

A pattern where a coding agent runs normally but sends every command it executes to a separate, locked-down sandbox.

An external sandbox separates where an agent thinks from where its commands run. The coding agent runs as usual on your machine or server. Every shell command or file edit it makes goes over a small protocol to a separate sandbox process. The sandbox is external to the agent, not necessarily to the computer, so both can run on the same laptop.

This fixes a weakness of sandboxes that live inside the agent. The agent can't modify the sandbox's rules or its own environment. The sandbox only sees the folders you mount, read-only or read-write. Network access is off unless you allow it, often through a proxy limited to approved hosts. The proxy can also inject API keys into requests to specific hosts, so the agent can use a service without ever seeing the secret.

Because the protocol is the contract, any agent can work with any sandbox. One implementation might be a Linux emulator in WebAssembly, another a local container, another a full virtual machine. You choose isolation strength separately from the choice of agent.

The same idea carries over to the browser. The agent loop runs on a server or in the page, and the sandbox is a Linux machine in the user's tab, driven through its terminal.