Skip to content
getredanPublic

About

Secure, local-first execution environment for AI coding agents

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Redan

Your agents run free. Your secrets stay put.

CI Security Audit Release License: BSD-3-Clause

What is redan?

redan runs an AI coding agent inside a libkrun microVM that boots in under a second. The agent gets a real Linux dev environment with your project mounted in, walled off from the rest of your machine:

  • Its own filesystem. It sees the project you mount, not your home directory, SSH keys, or dotfiles.
  • A network allowlist. Default-deny outbound; it reaches only the hosts you permit, over HTTPS, with no direct-IP or DNS escape.
  • Secrets it can't read. API keys are injected at the network layer, only for the hosts you allow. The agent sees a placeholder, never the real value, so a compromised agent has nothing to steal and nowhere to send it.

redan (/ɹɪˈdan/): a V-shaped fieldwork forming a salient angle toward the enemy.

Getting started

Redan requires Linux with KVM (/dev/kvm), libkrun and fuse3 (fusermount3, in every distro's fuse3 package).

Install libkrun:

# Arch
pacman -S libkrun

# Fedora
dnf install libkrun-devel

# Ubuntu/Debian (not yet in repos, build from source)
apt install build-essential libkrunfw-dev
git clone https://github.com/containers/libkrun
cd libkrun && make && sudo make install

Install redan:

Pre-built binaries for Linux x86_64 and aarch64, or build from source (needs Rust 1.99 or newer, rustup update stable gets you there):

cargo install --git https://github.com/getredan/redan.git

Verify:

redan doctor

Run an agent (zero-config)

claude setup-token     # prints a token that lasts a year
redan login claude     # paste it, nothing is echoed
cd ~/my-project
redan run claude

That's it. redan run claude picks up your token, builds the claude-code image if needed, mounts the current directory, allows Anthropic's API hosts, drops privileges to a non-root user, and drops you into an interactive Claude Code session. It prints what it chose so nothing is silent:

  Using image: claude-code
  Injecting CLAUDE_CODE_OAUTH_TOKEN (from redan login) for api.anthropic.com
  Mounting current directory → /workspace

redan run pi does the same for Pi, and redan run opencode for opencode with Anthropic models. Run redan run with no agent to auto-detect from the environment. Pass an initial prompt after --:

redan run claude -- "fix the failing test in api/users.py"

Git remote hosts are added to the network allowlist automatically so git push/pull works out of the box.

redan login keeps the token in ~/.config/redan/credentials, readable only by you, so it doesn't sit in the environment of every process your shell starts. For an API key, run redan login claude --env ANTHROPIC_API_KEY. An env var you export (ANTHROPIC_API_KEY or CLAUDE_CODE_OAUTH_TOKEN) still wins over the stored credential, and either way the guest only sees a placeholder. redan can also stage your ~/.claude credentials into the VM, though on Linux those rotate and go stale, so the token is the reliable choice for unattended runs.

The agent's home in the guest lasts from one session to the next in the same project, so onboarding and claude --continue work as on your machine. Each project and image gets its own directory under ~/.local/state/redan/homes/, which starts as a copy of the image's home. Delete it to start over. Whatever the session changes in the guest outside that home and your mounts is gone when it ends.

redan run is the opinionated path: it knows each agent's image, command, auth, and network policy. For full manual control over the image and command, use redan exec (below).

Any agent

Redan works with any command-line AI agent. Build an image, tell redan what to run and what hosts to allow:

redan image create myimage --packages "python3 nodejs npm"
redan exec --image myimage \
  --secret "API_KEY=env://MY_API_KEY:api.example.com" \
  --mount ./my-project \
  -c "my-agent --some-flag"

Or use redan.toml for repeatable setups:

image = "myimage"
command = "my-agent --some-flag"
interactive = true

[network]
allow = ["api.example.com", "registry.npmjs.org"]

[secrets.API_KEY]
value = "env://MY_API_KEY"
hosts = ["api.example.com"]

[mount.workspace]
source = "."
target = "/workspace"

[env]
MY_SETTING = "value"

redan init generates a config from project detection. redan init --claude adds a devcontainer with Claude Code, Node.js, and project-appropriate tooling.

Secrets

Secrets are injected into HTTPS request headers by the proxy on the host side. The agent only sees placeholder tokens. Format: ENV_VAR=value:allowed_hosts

# Literal
--secret "GITHUB_TOKEN=ghp_abc123:api.github.com"

# From host env var (read at startup, never passed to VM)
--secret "GITHUB_TOKEN=env://GITHUB_TOKEN:api.github.com"

# From HashiCorp Vault KV v2
--secret "API_KEY=vault://secret/myapp#api_key:api.example.com"

# Multiple hosts
--secret "API_KEY=sk-abc:api.example.com,cdn.example.com"

# From a file (one spec per line, # comments)
--secret-file .redan-secrets

env://, credential:// and vault:// keep secrets out of process listings. credential://NAME reads what redan login stored as NAME. Vault falls back to ~/.vault-token if VAULT_TOKEN is not set.

Note: Redan injects into HTTP headers only. Auth patterns that need secrets in request bodies (OAuth token exchanges, AWS SigV4), TLS handshakes (mTLS), or cookies are not supported for injection. Redan still provides VM isolation and network restriction for those cases, you just pass the credential via environment variable.

Network policy

Default-deny outbound. You must explicitly allow hosts:

redan exec --allow-host api.anthropic.com --allow-host registry.npmjs.org

Each entry is a hostname or a *.domain pattern: "*.amazonaws.com" matches any subdomain of amazonaws.com, but not amazonaws.com itself. IP addresses are refused, since the guest reaches every host by name through redan and an address would never match. Hosts required by secrets are included automatically, and so are the sandbox.network.allowedDomains from Claude Code's settings (the project's .claude/settings.json / settings.local.json and your own ~/.claude/ ones). When redan sets the agent up for you (redan run, or redan exec with no config file and no flags that set up the session), it also allows the agent's own hosts and your git remotes' hosts. Those imports can add hosts but can't turn the allowlist off. Git remotes only add plain hostnames, and an entry in Claude Code's settings that isn't a hostname or a *.domain pattern, like "*", is skipped with a warning. Pass --allow-host '*' yourself if you want allow-all.

Connections to private IP ranges (RFC 1918, loopback, link-local, cloud metadata) are blocked, except for hosts you named yourself with --allow-host, a --secret, your user config or the agent profile. Hosts that only a project's redan.toml, Claude Code's settings or your git remotes put on the allowlist never reach a private address, and neither does anything in allow-all mode. If your project needs an internal host, pass it with --allow-host. Domain fronting is blocked: HTTP Host must match TLS SNI.

Discover mode lets you figure out what hosts the agent needs:

redan run claude --discover
# or, for a custom image:
redan exec --image myimage --discover -c "my-agent --some-flag"

Redan allows all connections, prints the observed hosts at exit, and generates a [network] config block you can paste into redan.toml.

Browser support

For agents that need web access (research, testing, scraping), redan can launch headless Chrome on the host with CDP (Chrome DevTools Protocol) access from the guest:

redan exec --browser --allow-host "*.example.com"

Chrome runs on the host, not in the VM. Its outbound traffic goes through an allowlist proxy that enforces the same host restrictions as the main proxy, including SSRF protection for private IPs. The agent controls Chrome via CDP through port forwarding.

The guest gets these env vars:

  • REDAN_BROWSER=1
  • REDAN_BROWSER_HOST (gateway IP to connect to)
  • REDAN_BROWSER_CDP_PORT (CDP port, default 9222)

Chrome's sandbox stays enabled. The VM isolates the agent, Chrome's sandbox protects the host.

Requires Chromium or Google Chrome installed on the host. redan doctor checks for it.

Port forwarding

Forward TCP ports from guest to host, useful for dev servers, databases, or services running on the host that the agent needs to reach:

# Same port both sides
redan exec --forward 8080

# Different ports: guest connects to 3000, redan relays to host 8080
redan exec --forward 3000:8080

In redan.toml:

[network]
forward = ["8080", "3000:8080"]

The guest connects to the gateway IP on the guest port; redan relays to 127.0.0.1 on the host port.

Mounts

--mount /home/chris/project              # mounts to /workspace
--mount /home/chris/project:/code        # custom guest path
--mount /home/chris/.config/tool:ro      # read-only
--mount /home/chris/.ssh:/ssh-keys:ro    # host config, read-only

Uses virtio-fs for host directory sharing. The guest has read-write access by default. Append :ro for read-only. Git is your safety net for recovering from unwanted changes to mounted directories.

Every mount goes through a filter on the host that keeps the guest from changing files your machine runs or reads as configuration without asking: git hooks and config, .envrc, VS Code tasks and settings, Claude settings, .mcp.json, redan.toml and a few more. The guest can read them but not write, create, rename or remove them. Every .git directory is read-only too, except for what git writes there in daily use, so the guest can commit, branch, stash and rebase, but git config, git submodule init and git worktree add only work on your machine.

You can hide files from the guest and make more of them read-only with [files] in redan.toml or your user config:

[files]
hide = [".env", ".env.*", "*.key", "/secrets"]
read_only = ["docs/"]

The patterns work like .gitignore: one without a / matches at any depth, one with a / is anchored at the mount, and each covers everything below it. Hidden files look like they don't exist, even ones you create while the session runs. Every layer's rules apply, and redan prints the hidden patterns when a session starts, so a missing import in the guest can be traced back to them.

Config trust

A redan.toml in your working directory is read by redan on the host, before the VM boots, with your privileges. So a redan.toml from a repo you cloned could read your environment, mount your home directory, or write host files, none of which the sandbox would catch, because it runs before the sandbox starts. redan trust-gates it.

A config that only sets safe things (image, command, guest env, hosts in [network] allow, a literal secret, or a mount inside the project) loads with no prompt. A config that reaches for host authority has to be trusted first:

  • reading host env vars, stored credentials or Vault (env://, credential:// and vault:// secrets)
  • mounting a path outside the project, or setting rootfs
  • forwarding a host-local port, or writing a host audit_log / log_file
  • turning the network allowlist off with allow = ["*"]

When redan hits one of those and the config isn't trusted, it prints exactly what the config would be allowed to do and, in an interactive session, asks before continuing. Or trust it ahead of time:

redan trust              # review ./redan.toml, then trust it
redan trust path/to/redan.toml
redan untrust            # revoke

Trust is keyed by a hash of the file's contents (in ~/.local/state/redan/trust.json), so editing the config requires trusting it again. It's a local consent record, not a signature: it guards against an unreviewed config and against the sandboxed agent rewriting the mounted file, not against someone who already has your user account. See docs/security-model.md.

Admin policy

A team that rolls redan out can put a policy in /etc/redan/policy.toml. It only takes things away, and nothing you configure can loosen it:

version = 1
min_redan = "0.4.0"

[agents]
allow = ["claude"]

[network]
allow = ["api.anthropic.com", "registry.npmjs.org", "*.pythonhosted.org"]
forward_ports = [5432]

[files]
hide = [".env", ".env.*", "*.key"]

[protected]
remotes = ["git.example.com/finance/**"]
paths = ["/srv/checkouts/secret"]

With a policy in place:

  • only the listed agents run, through redan run, and as their profiles define them: no other image or user, the profile's command with only quoted arguments added, and no secrets but the agent's own credential, so a write-capable git token can't go in
  • a git push over HTTPS gets a 403 on every host. That covers git's own push protocol, not a forge's API: if a host in the ceiling accepts uploads, like a GitLab instance's commits API, a token the guest has can still write there, so keep tokens that can write out of the guest
  • [network] allow is the ceiling for every session's allowlist. A host you type with --allow-host outside it is refused, and one from a redan.toml, an agent profile or a secret is dropped with a warning, so a shared config keeps working under a stricter policy. Git remote hosts aren't added automatically
  • forwards need a host port from forward_ports
  • redan refuses --allow-host '*', --discover, --browser, copying credential files into the guest and an audit log outside the session dir, and closes the guest's port 22
  • its [files] rules apply on top of every project's
  • the session mounts the git checkout you're in as a whole, and starts the guest in your directory inside it. It refuses to start outside a repository, in a repository at your home or /, in a worktree, in a directory that holds another checkout, and in a repository whose remote (any of them, as host/path, its submodules' included) or path the policy protects. redan reads the remotes with git and only your PATH, HOME and XDG_CONFIG_HOME, so GIT_DIR and the other GIT_* variables can't point it elsewhere

A list you leave out allows nothing. Each session prints which policy it used, with its hash, and every refusal points at redan doctor, which shows what the policy allows, which credentials each allowed agent would use, and why redan won't use a policy that fails a check. It exits non-zero then, so install tooling can check it.

The file and every directory above it must belong to root and not be writable by group or others, like sudoers. If it fails a check or doesn't parse, redan refuses to start instead of running without it. version is the format, and min_redan makes an older redan say it needs updating instead of failing on a key it doesn't know.

Image management

redan image create myimage --packages "python3 pip" --run "pip install flask"
redan image import myimage --from ubuntu:24.04
redan image import myimage --dockerfile path/to/Dockerfile
redan image import myimage --devcontainer .devcontainer
redan image list
redan image update myimage    # rebuild from original source
redan image remove myimage

create builds Alpine-based images. import pulls from Docker images, Dockerfiles, or devcontainer configs. update remembers how the image was built and rebuilds from the same source. redan doctor warns about images older than 30 days.

Sessions

redan exec -d --name my-agent    # run in background
redan logs my-agent              # view audit trail (logfmt)
redan logs my-agent -f           # follow live
redan attach my-agent            # reconnect
redan stop my-agent              # SIGTERM, wait 3s, SIGKILL

redan sessions                   # list all
redan sessions show <id>         # details
redan sessions remove            # clean up exited sessions

Audit log

Every session records an audit trail automatically. View it with redan logs:

redan logs <session>
ts=2026-08-14T20:04:07Z severity=info event=dns hostname=example.com
ts=2026-08-14T20:04:07Z severity=warning event=reject host=example.com reason=not_allowed
ts=2026-08-14T20:04:07Z severity=info event=dns hostname=httpbin.org
ts=2026-08-14T20:04:08Z severity=info event=inject host=httpbin.org count=1
ts=2026-08-14T20:04:08Z severity=info event=connect host=httpbin.org

The default view is logfmt (greppable key=value lines). Event values are escaped so a crafted hostname can't forge a log line or drive the terminal.

redan logs <session> --json           # raw JSON for jq
redan logs <session> -f               # follow live (like tail -f)
redan logs <session> | grep event=reject   # find blocked connections

You can also write the audit log to a custom path:

redan exec --audit-log events.jsonl

Agent awareness

Redan tells the guest about its environment so agents can adapt instead of hitting mysterious "connection failed" errors:

  • REDAN=1 (running in a redan sandbox)
  • REDAN_NETWORK=restrict|deny-all|allow-all (policy mode)
  • REDAN_ALLOWED_HOSTS=host1,host2,... (permitted hosts)
  • /etc/redan/policy (human-readable policy file)

How it works

Guest VM (libkrun, <1s boot)
  |
  |  virtio-fs (project dir)
  |  virtio-net (ethernet frames over unix socket)
  v
smoltcp (userspace TCP/IP on host)
  |
  |-- UDP :53  -> synthetic DNS (per-host IP allocation)
  |-- TCP :22  -> transparent relay (allowlist checked)
  |-- TCP :80  -> rejected (HTTPS only)
  |-- TCP :443 -> TLS MITM proxy
  |     |-- SNI extraction, ephemeral cert
  |     |-- secret injection (headers, host-scoped)
  |     |-- response scrubbing (literal byte match)
  |     '-- forwarded to real upstream
  |-- TCP fwd -> port forwarding to host localhost
  v
internet (allowed hosts only)

DNS is synthetic (no queries leave the host), all traffic routes through the gateway (no direct IP access), and HTTP/1.1 only (HTTP/2 binary framing would bypass header parsing). SSH on port 22 is forwarded as-is with allowlist enforcement but no injection/scrubbing.

Security model

Redan's threat model: a compromised or malicious AI agent inside the VM tries to exfiltrate secrets or access unauthorized resources.

What redan prevents: agent reading real secret values, sending secrets to unauthorized hosts, making DNS queries to the internet, connecting directly to IP addresses, reaching hosts not in the allowlist.

Known limitations: scrubbing is literal byte match (doesn't catch base64/URL-encoded secrets), no request body inspection, HTTP/1.1 only. Primary defense is the host allowlist, not scrubbing. Scrubbing reduces accidental exposure; it's not a hard security boundary.

See docs/security-model.md for the full threat model and side-channel analysis.

Platform

Linux only, kernel 5.6 or later for openat2. Requires KVM (/dev/kvm). x86_64 and aarch64.

libkrun supports macOS via Hypervisor.framework but this is untested. No Windows support (WSL2 with KVM passthrough may work, untested).

Status

Alpha. The full chain works end-to-end: zero-config redan run claude through interactive Claude Code sessions with network policy enforcement, credential staging, and privilege separation. Pre-built binaries on GitHub Releases.

This code has not been through an independent security audit. Use at your own risk and report vulnerabilities responsibly.

Support

If redan is useful to you, consider buying me a coffee.

Acknowledgments

  • libkrun and libkrunfw for the microVM engine and guest firmware
  • smoltcp for the userspace TCP/IP stack
  • rustls and rcgen for TLS and certificate generation
  • Gondolin for the network-layer secret injection pattern

License

BSD-3-Clause

About

Secure, local-first execution environment for AI coding agents

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages