agvisor
gVisor (runsc) sandboxes for coding agents. Thin wrapper over the docker CLI: CPU/memory/pids limits, optional GNOME desktop over RDP.
Alpha, and not security-audited. Read Security before running code you don't trust.
Host setup (Linux VM or server)
Install gVisor, then register the runtime in /etc/docker/daemon.json and systemctl reload docker (a restart bounces every running container unless live-restore is on).
The two runtimeArgs are only needed for GUI sandboxes (systemd needs cgroup v2, sudo needs suid). Register them as a second runtime, so headless sandboxes keep the strict one, and pass runtime="runsc-gui" with gui=True:
{"runtimes": {"runsc": {"path": "/usr/local/bin/runsc"},
"runsc-gui": {"path": "/usr/local/bin/runsc",
"runtimeArgs": ["--in-sandbox-cgroup=v2", "--allow-suid"]}}}
(Putting the args on runsc itself also works and needs no runtime=, but then every sandbox on the host gets them.)
On AWS/Azure/GCP VMs: with network="bridge" a sandbox can reach the cloud metadata endpoint (169.254.169.254) and read the VM's instance credentials. Block it on the host (untested here): sudo iptables -I DOCKER-USER -d 169.254.169.254 -j DROP, or use network="none".
GUI image (x86_64), from the gVisor systemd post:
git clone https://github.com/google/gvisor.git && cd gvisor
docker build -t systemd-debian-gnome \
-f images/systemd-user/systemd-debian-gnome/Dockerfile.x86_64 images/systemd-user/systemd-debian-gnome
The image is ~8 GB and the build takes ~30 min on 2 vCPUs (checked on a 2 vCPU / 4 GB VM: peak ~1.5 GB RAM). A desktop needs about 0.7 GB RAM idle, so give it memory="1536m" or more.
Host firewall: if yours drops traffic from docker0 (e.g. INPUT -i docker0 -j DROP, a common way to keep sandboxes away from the host), the gateway can't reach a desktop on the default bridge: guacd hangs without an error. Create a network for desktops (docker network create desktops) and pass network="desktops". Your egress rules don't apply to it, so don't run untrusted code there.
Use
from agvisor import Limits
from agvisor.sandbox import create_sandbox # creates AND starts the sandbox
SMALL = Limits(cpus=1, memory="512m", pids=128) # define once, reuse for any number of sandboxes
with create_sandbox(limits=SMALL, lifetime=3600) as sb: # headless
r = sb.exec("python3 -c 'print(1+1)'", timeout=30)
print(r.returncode, r.stdout)
with create_sandbox(gui=True, limits=Limits(cpus=4, memory="6g")) as sb: # desktop
print(f"RDP 127.0.0.1:{sb.rdp_port} user=gnome password={sb.password}")
input("press enter to destroy")
sb = create_sandbox(host="ssh://user@my-vm") # same thing, on a remote VM/server (e.g. EC2, Azure)
sb.stop() # without `with`, you stop it yourself
| param | meaning |
|---|---|
image |
default ubuntu:24.04, or the GNOME image when gui=True |
gui |
GNOME desktop over RDP, with a random RDP password (not the image's gnome:gnome). start() waits for the desktop to boot: ~30-60 s |
runtime |
docker runtime, default runsc. With a separate GUI runtime: "runsc-gui". Must be a gVisor runtime: plain runc is refused for gui (it runs --privileged, which is only simulated under gVisor) |
limits |
Limits(cpus, memory, pids, shm, disk): default 2 cores, 2g, 512 processes, docker's /dev/shm size, 5g root disk. Zero or negative values are rejected (docker and runsc would read 0 as unlimited) |
network |
"bridge" (internet, default), "none" (headless only) or the name of a docker network you created |
lifetime |
seconds until the sandbox deletes itself, even if your process dies (headless only) |
idle_ttl |
seconds without an exec() before the sandbox deletes itself, even if your process dies (headless only). Expiry can lag by up to ~5s. See below |
name |
makes the sandbox resumable, see below |
host |
None = docker on this machine (or $DOCKER_HOST); "ssh://user@host" = docker on a remote VM/server |
sb.exec(cmd, input=None, timeout=120) runs sh -c cmd inside and returns a CompletedProcess; on timeout the command is killed and returncode is 124. That relies on GNU timeout, so use Debian/Ubuntu-based images (python:3.12-slim, ubuntu). On Alpine (busybox) the code is 143 and only the shell is killed: the children of a compound command (a; b) keep running. Also don't set an ENTRYPOINT in your image: agvisor starts it with sleep infinity as arguments.
Under gVisor, the limits behave differently from plain docker (checked on real runsc):
pidsbudgets the sandbox runtime's host threads, not guest processes: an idle sandbox already uses ~35. Keep the default (512): at 64–128, a fork storm madeforkfail withOut of memoryand, pushed harder, killed the sandbox.- Going over
memoryorpidskills the whole sandbox, not one process, and the host doesn't notice. Afterwardsexecreturnsreturncode1 or 128 withis not runningorWaitPIDin stderr. Callcreate_sandbox(name=...)again: it starts a fresh container on the same/workspacevolume. diskcaps the root filesystem (runsc'soverlay2annotation, checked on release-20261026.0): past it, writes fail withNo space left on deviceand the sandbox keeps running. Whole number +k/m/g/t:1.5gand2gbare rejected. It does not cover/tmp, which gVisor backs with RAM (counted inmemory), nor the/workspacevolume of a named sandbox: that is a plain host directory with no size cap, so a runaway agent can fill the host's disk through it. Until that has a cap, keep/var/lib/dockeron a disk of its own, and don't share it with anything you care about.tests/test_gvisor_disk.pychecks the cap against real gVisor.- Inside,
uname -rreports4.19.0-gvisorand/sys/fs/cgroupand/sys/class/netdon't exist (use/proc/net/dev).
Resuming a sandbox
with create_sandbox("python:3.12", name="my-project") as sb: # session 1
sb.exec("git clone https://github.com/me/repo && python -m venv .venv && .venv/bin/pip install -r repo/requirements.txt")
# the container is gone (CPU/RAM freed), /workspace is kept
with create_sandbox("python:3.12", name="my-project") as sb: # session 2, days later
sb.exec("ls -a") # -> repo/ .venv/ (cwd is /workspace)
create_sandbox(name="my-project").delete() # forget it: erases the data too
- Kept: everything under
sb.data_dir(/workspace; thegnomehome forgui=True), in a docker volumeagvisor-<name>. - Not kept: processes, and anything outside
data_dir(e.g.apt install): gVisor discards the rootfs overlay when the container is destroyed. Work in/workspace(venvs, repos, caches), or bake system packages into your image. - Keep everything: don't call
stop(). The container stays running and the nextcreate_sandbox(name=...)re-attaches to it with processes and installed packages intact. (limits/imageare then ignored: they were fixed at creation.) - The volume lives on the docker host. On a cloud VM, keep
/var/lib/dockeron a persistent disk (EBS / managed disk), not instance-store, and resume on the same VM. Don't set--overlay2=all:*in therunscargs: it would stop volumes persisting.
For a remote host the RDP port is on that host's 127.0.0.1: tunnel it with ssh -L.
network="none" cuts network access (headless only: GUI needs the published port).
Expiry and cleanup
from agvisor import list_sandboxes
sb = create_sandbox(name="u42", idle_ttl=900, lifetime=4 * 3600) # gone after 15 idle minutes, or 4h at most
for sb in list_sandboxes(host="ssh://user@my-vm"): # every agvisor sandbox on that docker host
print(sb.name); sb.stop() # exec(), stop() and delete() work on these handles
idle_ttl: the clock restarts when eachexec()starts and ends; background processes don't count.exec(timeout=)must be shorter thanidle_ttl(elseValueError), so a command can't outlive the sandbox. It is fixed at creation, likelimits.- A named sandbox that expires keeps its files: the next
create_sandbox(name=...)makes a fresh container on the same volume.delete()is what erases them: run it from your own retention job. list_sandboxes()also finds anonymous sandboxes left behind by a crashed process. Don'tstart()a stopped handle: it would make a fresh default-image container.
GUI in a web page (React, Next.js, Vue, plain HTML)
Browsers can't speak RDP, so there is a gateway in between: browser <-wss-> gateway/gateway.js <-> guacd <-RDP-> sandbox.
Start both on the docker host with the compose file (pip install 'agvisor[web]' for the token helper):
export AGVISOR_KEY=$(openssl rand -hex 32) # shared by the gateway and your backend; compose refuses to start without it
docker compose up -d --build # guacd + gateway, both on 127.0.0.1; gateway on :8090 (GATEWAY_PORT to change)
The compose file pins both images by digest, binds guacd to loopback (its image defaults to 0.0.0.0, an open RDP proxy on host networking), and runs the gateway as a non-root, read-only container. Linux only: both use the host network. Without Docker: cd gateway && npm install && npm start, plus guacd bound to 127.0.0.1.
Put the gateway behind your TLS reverse proxy (so the page uses wss://) and your auth. In your backend, after the user is authorised:
sb = create_sandbox(gui=True)
token = sb.desktop_token(bytes.fromhex(os.environ["AGVISOR_KEY"]), ttl=60) # server-side only: it holds the RDP password
# return {"gateway": "wss://your.host/desktop", "token": token} to the page
In the page, give the element a size and pass both values (the component is web/, npm package agvisor-desktop):
import "agvisor-desktop"; // React / Next.js ('use client'): safe to import during SSR, it does nothing on the server
<agvisor-desktop gateway={gateway} token={token} style={{ width: "100%", height: 600 }} />
<!-- Vue: compilerOptions.isCustomElement = (tag) => tag === "agvisor-desktop"; plain HTML: <script type="module"> -->
<agvisor-desktop :gateway="gateway" :token="token" style="width:100%;height:600px"></agvisor-desktop>
A new token reconnects. The element fires an error event (e.detail = message) when the connection fails or drops, e.g. a rejected or expired token: mint a fresh one and set it. TypeScript needs a JSX IntrinsicElements entry for the tag.
A token only has to be valid when the session opens, but anyone holding it can open one until ttl runs out.
In web/: npm test checks the token round trip against the real gateway with a fake guacd; npm run test:browser runs the component in real Chrome (render, mouse, keyboard, resize, errors, cleanup).
Security
This is alpha software and nobody has audited it. gVisor shrinks the part of the kernel that sandboxed code can reach; it is not a guarantee, and this library's own code has not been reviewed for flaws. Don't use it as the boundary for hostile multi-tenant workloads without a review of your own, and keep runsc up to date (tested with release-20261026.0). Known gaps:
- Whoever can run
dockeron the host controls every sandbox, and is effectively root on that host. agvisor adds no authentication or authorization: put your own in front of it. name=has no ownership check.create_sandbox(name="x")re-attaches to whatever running container is calledagvisor-x, removes a stopped one of that name, andlist_sandboxes()returns every sandbox on the host. If a tenant can choose the name, they can attach to, run commands in, stop anddelete()another tenant's sandbox. Build names yourself (e.g.f"{tenant_id}-{run_id}") and check ownership before you pass them in./workspacehas no size cap.Limits(disk=)only caps the root filesystem. The/workspacevolume of a named sandbox is a plain host directory, so a runaway or hostile process can fill the host's disk through it. Anonymous sandboxes have no volume: their writes fall underdisk(and RAM-backed/tmpundermemory). For named ones, put/var/lib/dockeron a disk of its own, so a full disk doesn't take other services down with it.- Sandboxes on one docker network can reach each other. That is Docker's default: every sandbox on
"bridge"(the default) or on a network you share between tenants can connect to the others' open ports. Usenetwork="none", a separate network per tenant or run, or a network created with-o com.docker.network.bridge.enable_icc=false(from Docker's documentation; not tested with agvisor). network="bridge"also reaches the outside: the internet, services listening on the host itself (through the bridge gateway), and on a cloud VM the metadata endpoint that serves instance credentials (see Host setup). Block what you don't want on the host's firewall, or usenetwork="none".gui=Trueruns--privileged. Under gVisor that only grants simulated capabilities; under plainruncit would be real, so agvisor refusesruncfor GUI sandboxes. The RDP password is random per sandbox and the gateway token is encrypted and authenticated, but anyone holding a token can open a session until it expires.
To report a vulnerability, email sadokbarbouche1@outlook.com instead of opening a public issue (details in SECURITY.md).
CI and dependency updates
.github/workflows/ci.ymlruns on every PR, every push tomain, and weekly (new advisories appear without commits):test(Python tests, the gateway token round trip, and the component in real Chrome),audit(pip-auditon the locked Python deps,npm audit+ registry-signature check onweb/),semgrep(code scan of the Python, the JS and the workflows)..github/dependabot.ymlopens weekly update PRs foruv,npmand the GitHub Actions themselves (minor+patch grouped, 7-day cooldown). Those PRs run the same checks.- Not configurable from a workflow, set these in the repo settings: make
test,auditandsemgreprequired checks onmain, and turn on Dependabot alerts. - Run it locally:
uv run python tests/test_args.py, then inweb/:npm testandnpm run test:browser(afternpm ciin bothweb/andgateway/), plusuvx pip-audit …,uvx semgrep …(exact commands inci.yml).
Metadata
Release files for agvisor 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agvisor-0.1.0.tar.gz | 18.9 kB | With provenance | Details for agvisor-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agvisor-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for agvisor-0.1.0-py3-none-any.whl |
Total release size: 35.9 kB
Release files / agvisor-0.1.0.tar.gz
| Download URL | agvisor-0.1.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
50bb2b9b442b822c4df0340ff75e5311576af2598d34da4f045002eedd621031
|
|
BLAKE2b-256 checksum How to use checksums |
d50a852de6ccfc66ab833436ba9a22aaff25a183f85c49e539996a0b1ee11d1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logRelease files / agvisor-0.1.0-py3-none-any.whl
| Download URL | agvisor-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a25af39af6a5e5f106557950fe7f1ca85bce5a9564b3532e175937c9ebd0624
|
|
BLAKE2b-256 checksum How to use checksums |
d5abc43c3f3b93121f0197c6f2062b55267c15a3370ff167845d56ce2c386902
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logSecurity for agvisor 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for agvisor-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.