Skip to content

feat(git): run upstream git as a WASI guest (git-wasi) - #3067

Open
andreaTP wants to merge 1 commit into
everruns:mainfrom
andreaTP:feat/git-wasi
Open

andreaTP wants to merge 1 commit into
everruns:mainfrom
andreaTP:feat/git-wasi

Conversation

@andreaTP

@andreaTP andreaTP commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

This started as an exploration spike. It was looking good, so I thought it was
worth sharing to see if it aligns with where you want git support to go. A
second step is ready on top of this one: running git's hooks, aliases and
editor commands in Bashkit's own interpreter.

Maintainer decision needed: licensing. git is GPL-2.0-only. This PR
ships it in its own crate. The alternatives are listed under Risk.

What changed

With the new opt-in git-wasi feature, git runs upstream git 2.55 compiled
to wasm32-wasip1 instead of the simulated git. It is configured as before,
through BashBuilder::git(GitConfig). Without the feature, nothing changes.

  • Commands: git's own commands and output, on real .git repositories in
    the VFS. This includes merge, rebase, stash, gc, and local clone, fetch
    and push.
  • HTTPS remotes: clone, fetch and push go through HttpClient, after
    GitConfig's remote allowlist. Credentials never reach git.
  • Other programs: nothing but git runs. Hooks, ! aliases, editors and
    pagers are refused, and ssh and git:// can't connect.
  • Limits: each command has limits on processes, time, memory and output,
    and is charged to the execution budget.
  • git-wasi-native: compiles git to machine code, like cpython-native.

How it runs:

  • Patch: git's only change is a 33-line patch to run-command.c. Child
    processes use git's existing Windows spawn path, and start_async() asks
    the host to copy the instance instead of forking.
  • Shared host: CPython's WASI host moves to builtins/wasi_host.rs, and
    both guests use it.
  • New crate: bashkit-git-wasm carries the module (1.1 MB). It can be
    rebuilt with guest/build.sh.

Why

The simulated git covers about 20 subcommands and has no network. Agents
expect git's behavior and output.

We first tried rewriting git on gitoxide and stopped at ~17.8k lines, with
most of git still missing. Running git itself takes ~1.5k lines of Rust and
~500 of C.

Before / After

Before:

$ git merge feature
git: 'merge' is not a git command. See 'git --help'.
$ git clone https://github.com/org/repo
git clone: network operations not supported in virtual mode

After:

  • Differential tests: git_wasi_tests.rs runs 52 steps in Bashkit and in
    host git, and requires identical output. The steps include merge, rebase,
    clone, push and pull.
  • fsck: host git fsck --strict accepts every repository Bashkit wrote.
  • HTTPS: tested against git http-backend.

Timings are Criterion medians on a repository with 200 commits:

Command Pulley Native code Host git
status --short 10 ms 2.2 ms ~6 ms
log --oneline 75 ms 19 ms ~11 ms
local clone 335 ms 293 ms ~43 ms

Risk

Medium. The feature is opt-in and off by default.

  • License (your call):
    • A, this PR: bashkit-git-wasm is GPL-2.0-only AND MIT AND Zlib,
      with a deny.toml exception for that crate only. Bashkit stays MIT, and
      git runs as a separate sandboxed program.
    • B: don't ship the module. Embedders build it and set
      BASHKIT_GIT_WASM. The crate becomes MIT, except guest/patches/.
    • C: keep git out of Bashkit. This needs the WASI host made public.
  • Shared WASI host: it now also serves CPython, and CPython's suites pass.
  • Known limits and threats: L-GITW-001 to 008 and TM-GIT-016 to
    022.

Checklist

  • Tests added or updated: differential tests against host git, HTTPS,
    security, fuzz targets and a benchmark.
  • Backward compatibility considered: opt-in feature, existing GitConfig
    API.

Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

With the opt-in git-wasi feature, `git` configured through
BashBuilder::git(GitConfig) runs upstream git 2.55 compiled to
wasm32-wasip1 instead of the simulated git: every command git implements
in C, git's own output, real repositories on the VFS, child processes
(merge, rebase, stash, local clone, fetch and push) and HTTPS remotes
through HttpClient after GitConfig's remote allowlist.

- One 33-line patch to git's run-command.c: start_command() uses git's
  Windows spawn path, start_async() asks the host to copy the process and
  call one function (fork_call). Host interface `bashkit_proc`: pipe, dup,
  dup2, spawn, fork_call, waitpid.
- CPython's WASI host is shared in builtins/wasi_host.rs, with bounded
  pipes, /dev/null, a notification-based poll_oneoff and fork support.
- Limits per command: 64 processes, the shell deadline (<= 120 s), 256 MB
  memory each, 16 MB output; every process is charged to the execution
  budget and aborted with the command. Programs other than git are refused.
- New crate bashkit-git-wasm (GPL-2.0-only AND MIT AND Zlib) ships the
  module and precompiles it; deny.toml allows GPL-2.0-only for it only.
- Differential tests against host git, HTTPS against git http-backend,
  security tests, two fuzz targets, a Criterion bench, CI and publish
  wiring, knowledge (git-wasm runtime, TM-GIT-016..022, L-GITW-*).

@bashkit-pr-reviewer bashkit-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the WASI-host side (git_wasi/mod.rs, remote.rs), the run-command patch, the compat shims, GitConfig allowlist, HttpClient redirect policy, knowledge/runtimes/git-wasm.md + threat-model entries, and the new integration tests. The sandboxing architecture is sound (no host FD/network outside HttpClient, fail-closed spawn gate, process/memory/output caps on both spawn paths). Three findings below, one blocking.

procs.reserve()?;
// git's HTTP transport: the host speaks the remote-helper protocol.
#[cfg(feature = "http_client")]
if let ("remote-https" | "remote-http", Some(url)) = (args[1].as_str(), args.get(3).cloned()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P0] resolve() rejects the helper before the helper branch runs, so HTTPS clone/fetch/push cannot work. spawn() calls resolve(path, &argv)? first (mod.rs:606), and resolve() returns ENOENT for path git-remote-https: the name strips to remote-https, which is not in DASHED (mod.rs:647), and it is not git or sh (mod.rs:651-676). But git's transport-helper spawns exactly git-remote-https <remote> <url> (dashed argv[0]), never git remote-https ..., so the ("remote-https"|"remote-http", args.get(3)) branch at mod.rs:616 is dead for real transports and every HTTPS operation fails at exec. Two corroborating signs: dashed argv carries the URL at index 2 while the branch reads args.get(3) (the shape only a literally-typed git remote-https <r> <u> has), and the resolve unit test covers git-st/vim rejection but has no git-remote-https acceptance case. The new clone_fetch_push_over_https_match_the_server test (tests/integration/git_wasi_tests.rs:524) exercises this path and should fail. Fix: intercept the helper before resolve() (match raw path/argv[0] git-remote-http(s)), or extend DASHED and map to ["git", "remote-https", remote, url] with the URL index corrected.

@chaliy chaliy Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This P0 appears to be a false positive at head 6560059874c52057ec5723b9e0264d9d50e3d15f.

Upstream git 2.55's get_helper() appends remote-https, the remote name, and the URL, then sets helper->git_cmd = 1. The Windows spawn path selected by this PR's WASI patch calls prepare_git_cmd() before mingw_spawnvpe(). Consequently the host receives ["git", "remote-https", remote, url], which resolve() accepts, with the URL correctly at index 3.

The clone_fetch_push_over_https_match_the_server test also passed in both the Pulley and native runs in CI job 144247012230. The asserted dashed invocation is therefore not the path taken here; adding these helpers to DASHED is unnecessary for this transport path.

Local verification after installing the pinned Rust 1.100.0 toolchain: cargo test --locked -p bashkit --features git-wasi,http_client --lib --test integration -- git_wasi passed all 4 unit tests and 14 integration tests, including clone_fetch_push_over_https_match_the_server.

let mut env: Vec<(String, String)> = ctx
.env
.iter()
.filter(|(k, _)| !k.starts_with("__BASHKIT_") && !k.starts_with("GIT_CONFIG_"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Forced env vars lose to sandbox env because of duplicate order. ctx.env is only filtered for __BASHKIT_*/GIT_CONFIG_* (mod.rs:209), then .sort()ed, and the forced values (GIT_CONFIG_NOSYSTEM=1, GIT_EDITOR=:, GIT_PAGER=cat, GIT_TEMPLATE_DIR=...) are appended last (mod.rs:221-240). GuestState keeps that Vec order and environ_get exposes it in order, while wasi-libc getenv returns the first match — so a sandbox-supplied GIT_EDITOR/GIT_PAGER/GIT_CONFIG_NOSYSTEM/GIT_TEMPLATE_DIR silently overrides the forced value, and other GIT_* (GIT_SSH_COMMAND, GIT_ASKPASS, GIT_EXTERNAL_DIFF, ...) plus PAGER pass through unfiltered. Impact today is fail-closed only because resolve() refuses to exec anything but git and config reads stay inside the VFS — but the documented forcing ("Settings that would start other programs are forced through GIT_CONFIG_*", mod.rs:12-14) does not hold. Fix: strip all GIT_* (and PAGER/EDITOR) from ctx.env except an explicit allowlist, and emit forced entries first / dedup.


/// A receive-pack request: commands, a flush, then the pack unless every
/// command deletes.
async fn read_push(&mut self) -> Option<Vec<u8>> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] read_push buffers the whole pack in host memory with no cap (remote.rs:172-196): after the flush it does req.append(&mut self.buf) then reads stdin to EOF into req. MAX_OUTPUT (16 MiB) caps guest stdio, not this host-side buffer, so a large push duplicates the entire pack in host RAM (bounded in practice only by VFS/repo sizes). Consider applying the same output/memory ceiling here (and a shared cap for read_request), returning a clean error past it.

@bashkit-pr-reviewer

Copy link
Copy Markdown

Review summary (head 6560059)

Verdict: promising direction and a well-documented change, but requesting changes — HTTPS remotes look unreachable as written ([P0] below), so the headline feature needs a fix plus a passing clone_fetch_push_over_https_match_the_server run.

Findings: 1 P0, 1 P1, 1 P2 (see inline review).

  • P0 git-wasi-remote-helper-unreachable: spawn() runs resolve() first, which returns ENOENT for git-remote-https (remote-https ∉ DASHED), so the helper branch checking args[1] == "remote-https" is dead for real transports; the branch's args.get(3) URL index also only matches a hand-typed git remote-https, not git's dashed argv (URL at index 2).
  • P1 git-wasi-env-forcing-inverted: forced GIT_* values are appended after sorted sandbox env and wasi-libc getenv returns the first match, so sandbox GIT_EDITOR/GIT_PAGER/GIT_CONFIG_NOSYSTEM/GIT_TEMPLATE_DIR win over the forced values. Fail-closed today via the spawn gate, but the forcing control doesn't hold as documented.
  • P2 git-wasi-push-buffer-uncapped: read_push accumulates the whole pack in host memory with no cap; MAX_OUTPUT doesn't cover it.

Checked and looks good: no host FD/network leakage (sockets/getaddrinfo stubbed, HttpClient only, redirects disabled with non-200 → error), service allowlisted to two values, fork_call also calls reserve() (process cap covers both spawn paths), procs.abort_all() on completion, pkt-line parsing ends at EOF, credentials stay in HttpClient, knowledge (runtimes/git-wasm.md, threat-model TM-GIT entries), limitations.md, and decisions-as-comments all updated per AGENTS.md.

Could not review: artifacts/git.wasm.xz wasn't in my checkout snapshot (large-file filter), so the binary itself is unverified; and per this project's setup I reason from code only (no build/test run) — please confirm the HTTPS integration test passes after the P0 fix. The GPL-2.0-only licensing question the author flagged is a maintainer decision, left open deliberately.

@chaliy chaliy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 6560059874c52057ec5723b9e0264d9d50e3d15f with Rust 1.100.0. The existing git WASI slice passed locally: 4 unit tests and 14 integration tests, including the HTTPS clone/fetch/push test. Two additional local probes reproduced the inline findings below.

The argumentless-child panic is contained by the existing builtin panic boundary, so I have classified it as P2. My earlier concern about child cleanup was not reproduced through Bash::exec: request-budget cleanup cancelled the pending VFS read, so I am not posting it as a confirmed defect.

procs.reserve()?;
// git's HTTP transport: the host speaks the remote-helper protocol.
#[cfg(feature = "http_client")]
if let ("remote-https" | "remote-http", Some(url)) = (args[1].as_str(), args.get(3).cloned()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Check for a subcommand before indexing child argv

With git-wasi,http_client, git -c alias.x='!git' x starts a child whose argv is just ["git"]. resolve() accepts that vector, then args[1] panics here. Reproduced locally at this head: index out of bounds: the len is 1 but the index is 1. The existing builtin panic boundary contains the unwind, but the command returns git: builtin failed unexpectedly instead of git's normal usage output. Please use checked access for the helper match and cover an argumentless child git invocation in a regression test.

Comment on lines +293 to +295
let mut result = ExecResult::with_code(out.stdout, code);
result.stderr = stderr.into();
Ok(result)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Propagate the guest output truncation flag

Output::write() discards bytes beyond the shared 16 MiB cap and sets out.truncated, but this return path ignores that flag. With the outer stdout limit raised to 32 MiB and sufficient intermediate-memory budget, a local probe reading a 17 MiB blob through git cat-file blob returned exit code 0, exactly 16,777,216 stdout bytes, and both truncation flags false. Callers therefore receive incomplete blob/archive data presented as complete output. Please propagate truncation into ExecResult and report it, as the CPython return path already does.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants