A throwaway Linux box for AI agents: run code in a gVisor sandbox, files in, files out.
Note
Kandang is experimental and still early. Things may change between releases, so don't make it your only sandbox yet.
Your agent sends Python or bash plus some input files. Kandang runs them in a fresh gVisor sandbox with no network and sends back stdout, stderr and whatever the code wrote to /work/out. The sandbox, its cgroup and its files are gone when the run ends.
Kandang never holds a secret. Anything that needs an API key stays in your agent, which fetches the data first and passes it in as a file.
- One endpoint,
POST /v1/runs, guarded by a bearer token. Plus an unauthenticatedGET /health. - An MCP server at
POST /mcp(Streamable HTTP, stateless) with oneruntool, so any MCP client can use it. Charts come back as images, other files as embedded resources. - Every run gets its own gVisor sandbox: no network, read-only root, non-root user (uid 10001), no capabilities,
noNewPrivileges, and its own pid, network, ipc, uts and mount namespaces. - Hard caps per run through cgroup v2: 1 GiB memory with no swap, one CPU, 256 host pids, 64 processes inside, 60 s default and 300 s max timeout.
- Input and output files are base64 in JSON. Names are cut to a basename, and output symlinks are never followed.
- A small queue: 2 runs at once, 10 waiting, then
429withRetry-After. - The sandbox image ships Python with numpy, pandas, matplotlib, Pillow, openpyxl, pypdf, python-docx and requests, so an agent can turn a CSV into a chart or a spreadsheet. Charts come out in a house style (dark, Inter, colorblind-checked colors) without any styling code.
Kandang drives runsc directly. There's no Docker on the run path and no Docker socket anywhere. The process starts straight inside the run's cgroup (clone3 with CLONE_INTO_CGROUP), so the limits apply from the first instruction. A timeout kills the whole cgroup.
| Part | Path | Built with |
|---|---|---|
| Server | apps/server |
Go (standard library only, no cgo), gVisor runsc, cgroup v2 |
| Sandbox image | image/ |
Alpine, Python, pandas, matplotlib |
| Deploy | deploy/ |
Bash, OrbStack, systemd, nftables |
| Website and docs | apps/site |
Next.js (static export), Fumadocs, Tailwind CSS |
You need an Apple silicon Mac with OrbStack, Docker (OrbStack's is fine) and Go (the version in apps/server/go.mod). Kandang runs in an isolated OrbStack machine that can't see the Mac's files. For a plain Linux host, see Self-hosting.
machine-setup.sh creates the isolated machine, installs runsc and generates the token. deploy.sh builds the binary and the sandbox image and starts the service. show-token.sh prints the bearer token, in a terminal only.
git clone https://github.com/zakiego/kandang && cd kandang
deploy/machine-setup.sh
deploy/deploy.sh
deploy/show-token.shThen, in the same terminal, set the URL and read the token. read waits for you: paste the token and press Enter.
export KANDANG_URL=http://kandang.orb.local:8080
read -rs KANDANG_TOKEN && export KANDANG_TOKENSend a run:
curl -s $KANDANG_URL/v1/runs \
-H "Authorization: Bearer $KANDANG_TOKEN" \
-H "Content-Type: application/json" \
-d '{"language":"python","code":"print(sum(range(10)))"}'{"exitCode": 0, "timedOut": false, "durationMs": 412, "peakMemoryMb": 21.3, "stdout": "45\n", "stderr": "", "stdoutTruncated": false, "stderrTruncated": false, "files": []}MCP clients connect to $KANDANG_URL/mcp with the same token. The quick start goes on to send a CSV in and get a chart back.
The full request and response shapes, limits and error codes are in the API docs.
Every setting is a flag or an environment variable, and flags win. kandang serve -h lists them. The systemd unit reads overrides from /etc/kandang/kandang.conf, one KEY=value per line. deploy/kandang.conf.example has every key with its default.
| Env | Flag | Default | What it does |
|---|---|---|---|
KANDANG_LISTEN |
-listen |
:8080 |
Address to listen on |
KANDANG_TOKEN_FILE |
-token-file |
/etc/kandang/token |
File holding the bearer token. Must be mode 0600 or stricter and at least 32 characters |
KANDANG_RUNSC |
-runsc |
runsc |
Path to the runsc binary |
KANDANG_ROOTFS |
-rootfs |
/var/lib/kandang/rootfs |
Unpacked sandbox image, mounted read-only |
KANDANG_STATE_DIR |
-state-dir |
/var/lib/kandang/state |
runsc state and per-run dirs |
KANDANG_CGROUP_ROOT |
-cgroup-root |
/sys/fs/cgroup |
cgroup v2 mount |
KANDANG_MAX_RUNNING |
-max-running |
2 |
Runs at once |
KANDANG_MAX_WAITING |
-max-waiting |
10 |
Runs waiting for a slot before 429 |
KANDANG_MEMORY_MB |
-memory-mb |
1024 |
Memory per run in MiB, no swap |
KANDANG_PIDS |
-pids |
256 |
pids.max per run, gVisor threads included |
KANDANG_PROCS |
-procs |
64 |
Processes per run inside the sandbox |
KANDANG_DEFAULT_TIMEOUT_SEC |
-default-timeout-sec |
60 |
Timeout when a run doesn't set one |
KANDANG_MAX_TIMEOUT_SEC |
-max-timeout-sec |
300 |
Largest timeout a run may ask for |
The token is never set through an env var. deploy/machine-setup.sh generates it inside the machine and only deploy/show-token.sh prints it.
The scripts in deploy/ target an isolated OrbStack machine (Debian, arm64). The server itself only needs Linux, runsc, cgroup v2 and nftables:
- Install
runscand make sure cgroup v2 is mounted with thememory,pidsandcpucontrollers. - Build the server into
/opt/kandang/bin/kandang, where the unit expects it. - Build
image/Dockerfile, export a container and unpack it into/var/lib/kandang/rootfs. - Write a random token of at least 32 characters to
/etc/kandang/tokenwith mode 0600. - Set up nftables first: the unit requires
nftables.service, so starting it starts nftables. Put Kandang'stable inet kandang_egressblock in/etc/nftables.conf, without the stockflush rulesetif the host has other rules, and enable nftables. The block drops everything the host sends to private addresses, so add anacceptline first for a resolver or mirror the host needs on one. - Install
deploy/kandang.serviceand start it.kandang checkverifies everything without writing anything.
The commands are in the self-hosting docs. Don't run deploy/machine-inside.sh on a host that has firewall rules of its own: it replaces the whole nftables ruleset.
Keep the API on a private network. It runs code for anyone with the token, so put it behind your own network boundary rather than on the open internet. The self-hosting docs cover the machine setup, the egress firewall and why the service runs as root.
The unit tests run anywhere, without runsc:
cd apps/server
gofmt -l .
go vet ./...
go test ./...To work on the website, which starts at http://localhost:4895:
pnpm install
pnpm dev:siteThe integration tests need Linux, root, runsc and the rootfs. See apps/server/README.md for how to run them in a throwaway machine.
Bug reports and small fixes are welcome. CONTRIBUTING.md has the setup and the conventions, and the code of conduct applies. Report a vulnerability privately, the way SECURITY.md describes.