8000 GitHub - zakiego/kandang: A throwaway Linux box for AI agents: run code in a gVisor sandbox, files in, files out · GitHub
[go: up one dir, main page]

Skip to content
< 7FFF link rel="preload" as="image" href="https://github.githubassets.com/assets/changelog-f3cfe2d3a6b4818b.webp"/>
zakiegoPublic

About

A throwaway Linux box for AI agents: run code in a gVisor sandbox, files in, files out

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Kandang

A throwaway Linux box for AI agents: run code in a gVisor sandbox, files in, files out.

Website · Docs · Changelog

Note

Kandang is experimental and still early. Things may change between releases, so don't make it your only sandbox yet.

Kandang: a throwaway Linux box for your AI agent

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.

Features

  • One endpoint, POST /v1/runs, guarded by a bearer token. Plus an unauthenticated GET /health.
  • An MCP server at POST /mcp (Streamable HTTP, stateless) with one run tool, 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 429 with Retry-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.

How it works

How a Kandang run works: your agent posts to /v1/runs, kandang stages the files and a cgroup, gVisor runs the code with no network, kandang collects the outputs and cleans up, and the agent gets the exit code, stdout, stderr and files back

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.

Stack

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

Quick start

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.sh

Then, 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_TOKEN

Send 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.

Configuration

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.

Deployment

The scripts in deploy/ target an isolated OrbStack machine (Debian, arm64). The server itself only needs Linux, runsc, cgroup v2 and nftables:

  1. Install runsc and make sure cgroup v2 is mounted with the memory, pids and cpu controllers.
  2. Build the server into /opt/kandang/bin/kandang, where the unit expects it.
  3. Build image/Dockerfile, export a container and unpack it into /var/lib/kandang/rootfs.
  4. Write a random token of at least 32 characters to /etc/kandang/token with mode 0600.
  5. Set up nftables first: the unit requires nftables.service, so starting it starts nftables. Put Kandang's table inet kandang_egress block in /etc/nftables.conf, without the stock flush ruleset if the host has other rules, and enable nftables. The block drops everything the host sends to private addresses, so add an accept line first for a resolver or mirror the host needs on one.
  6. Install deploy/kandang.service and start it. kandang check verifies 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.

Development

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:site

The integration tests need Linux, root, runsc and the rootfs. See apps/server/README.md for how to run them in a throwaway machine.

Contributing

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.

License

MIT

About

A throwaway Linux box for AI agents: run code in a gVisor sandbox, files in, files out

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0