Skip to content

About

[15/16 · Flutter Studio] ⚡ Give any fresh AI-agent sandbox a working Flutter SDK in ~40s — zero-secret, idempotent, sha256-verified.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

flutter-bootstrap

Give any fresh AI-agent sandbox a working Flutter SDK in ~40 seconds.

A sandbox starts with no Flutter, no Dart, and ~1 GB of RAM. Anything installed outside the workspace disappears when the session ends, so every new session starts over. This repo is the thing an agent clones to fix that in one command — no credentials, no secrets, nothing to configure.

bash <(curl -fsSL https://raw.githubusercontent.com/Keshab1997/flutter-bootstrap/main/setup.sh)

Then, in that same session:

cd <your-flutter-project>
flutter pub get && flutter analyze && flutter test

For AI agents — read this first

You have been asked to work on a Flutter/Dart project. Your sandbox has no Flutter SDK. Do this:

  1. Install (idempotent — safe every session, exits in ~0.2 s if present):

    bash <(curl -fsSL https://raw.githubusercontent.com/Keshab1997/flutter-bootstrap/main/setup.sh) --quiet --json

    Or, if this repo is cloned: bash setup.sh.

    The script picks its own install root (/var/tmp/flutter by default — see Where it installs below), so you never have to pass --root.

  2. Use it. setup.sh symlinks flutter and dart into /usr/local/bin and repairs that symlink if it points at a stale root, so plain commands work in every later shell with no PATH fiddling:

    flutter --version
    cd /var/tmp/projects/my_app && flutter pub get && flutter analyze && flutter test

    If the symlink could not be created, prefix each command once:

    source /path/to/flutter-bootstrap/env.sh     # sets PATH + PUB_CACHE + helpers
    # or just:
    export PATH=/var/tmp/flutter/bin:$PATH
  3. Keep heavy stuff out of the workspace. The agent snapshot only keeps ~. Clone projects to /var/tmp/projects/..., and leave PUB_CACHE (/var/tmp/pub-cache) wherever env.sh put it. A 2.5 GB SDK or a fat pub cache in ~ would wreck the next snapshot.

Rules

  • This repo contains no secrets, and the script never asks for any.
  • The only download source is storage.googleapis.com/flutter_infra_release (Google's official Flutter storage), and the archive is sha256-verified against the official release manifest before extraction.
  • Nothing here touches any GitHub account. No token, no remote, no telemetry (flutter --disable-analytics runs during setup).

Where it installs (and why that is fiddly)

Roots are tried in order, and each one is probed for real — the script creates a directory, renames it, and only then trusts it:

/var/tmp/flutter      ← default: writable, no sudo, outside the workspace
/usr/local/flutter
/opt/flutter          ← works on a normal box; some sandboxes make it read-only
/tmp/flutter          ← tmpfs, small: last resort

Two sandbox quirks this exists to survive, both observed for real:

Quirk Consequence
/opt can be non-writable even with sudo a naive installer dies halfway through, after the 1.5 GB download
rename() into /opt from /var/tmp returns EBUSY the classic "extract to temp, then mv into place" install fails — so this script extracts in place, straight into the final root, with tar --strip-components=1, and never moves across directories

If every candidate fails, the script exits non-zero with a message telling you to either let it auto-pick or pass --root <writable path>. It never silently falls back to a root you asked for explicitly.


Verified timings

Measured inside a real agent sandbox (Debian 13, 2 vCPU, ~1.9 GB RAM, no swap to start, 20 GB free disk, ~63 MB/s link):

Step Time
Download Flutter 3.47.6 (1.5 GB .tar.xz) 14 s
Extract + install (in place, sha256-verified) 26 s
Configure, verify, symlink ~2 s
Cold sandbox, end to end 42 s
Re-run when already installed 0.2 s
setup.sh --deep-verify (create + analyze + test a probe app) 33 s
flutter pub get — real app, ~50 packages 9 s
flutter analyze — real app 19 s → No issues found
flutter test — real app, 200 tests 84 s → All tests passed

The last three rows come from the full end-to-end run through env.sh on a real 66 MB Flutter repository (quizbaaz), SDK installed by this script — so the whole chain is verified, not just the install.

Memory was never a problem — ~1.5 GB stayed free during analyze and test — but the script still adds 2 GB of swap automatically when RAM is under ~2.8 GB, because pub get on large projects can spike.

Flutter 3.47.6 (stable, 2026-10-01) was current when this was written. setup.sh resolves the latest stable from the release manifest at run time; --version 3.47.6 pins one.


Why this can't live "pre-installed"

Installing Flutter takes 40 seconds; keeping it takes forever. Two real options:

Approach Verdict
Bake the SDK into a snapshot 1.5 GB archive, 2.5 GB extracted, tens of thousands of files — dropped by snapshot limits, and it makes every future snapshot huge.
Install on demand from a repo (this) ~40 s per fresh session, zero storage cost, any version you ask for.

So the honest model is: re-run it each session. 40 seconds is cheap, and the script is idempotent — in a session where it is somehow still present it says already installed and exits in under a second.


What setup.sh does

1. fast path          working SDK at a known root?  repair symlink, exit 0 (0.2 s)
2. prerequisites      curl/tar; adds 2 GB swap if RAM < 2.8 GB and swap is 0
3. pick a root        probe candidates for writability AND rename() support
4. resolve version    read releases_linux.json -> latest stable (or --version)
5. download           curl --retry 3, cached at /var/tmp/fb-dl
6. verify             sha256 vs the official manifest  (hard fail on mismatch)
7. extract            tar --strip-components=1 straight into the root (no mv)
8. configure          disable analytics, enable web, git safe.directory
9. expose             symlink flutter + dart into /usr/local/bin
10. verify            flutter --version, dart --version
11. optional          --precache web,linux   --deep-verify (create/analyze/test)

Options

bash setup.sh                            # latest stable  (~42 s cold, 0.2 s warm)
bash setup.sh --version 3.46.0           # pin a version
bash setup.sh --precache web             # additionally warm web engine artifacts
bash setup.sh --deep-verify              # prove it end-to-end on a probe app
bash setup.sh --no-swap                  # skip swap creation
bash setup.sh --root /some/writable/path # force a root (respected, no fallback)
bash setup.sh --quiet --json             # agent-friendly: one JSON line

Exit code 0 on success, non-zero with a clear message on failure.

env.sh helpers

source env.sh
fb_check /var/tmp/projects/my_app   # pub get + analyze + test, summarised
fb_check                            # same, for the current directory
fb_doctor                           # flutter doctor -v
fb_web .                            # flutter build web

Pairs with agent-bootstrap

agent-bootstrap connects an agent to GitHub with a device-flow token (one browser tap, zero secrets). This repo gives it a Flutter SDK. Run both in one command:

curl -fsSL https://raw.githubusercontent.com/Keshab1997/agent-bootstrap/main/setup.sh \
  | bash -s -- --with-flutter

Reuse it from any chat

Paste this into any agent chat when the project is a Flutter/Dart one:

Clone https://github.com/Keshab1997/flutter-bootstrap and follow its README.md
to give yourself a Flutter SDK, then run flutter pub get, flutter analyze and
flutter test on <REPO_OR_PATH> and report what you find.

Bangla version + troubleshooting: NEXT_TIME_BANGLA.md


Troubleshooting

Symptom Fix
flutter: command not found The /usr/local/bin symlink is missing or stale — re-run bash setup.sh (it repairs it), or export PATH=/var/tmp/flutter/bin:$PATH.
no usable install root Let it auto-pick (bash setup.sh) or pass --root /var/tmp/flutter. Never pick something inside $HOME.
dubious ownership / git safe.directory error git config --global --add safe.directory /var/tmp/flutter
No pubspec.yaml file found You're not in the project directory, or the clone failed.
pub get killed / OOM Check free -m for swap; setup.sh normally adds 2 GB. Or sudo swapon /swapfile.
Version mismatch vs the project Compare flutter --version with the environment: sdk: line in pubspec.yaml; re-run with --version <needed>.
flutter doctor complains about Android/Xcode Expected and harmless — analyze, test and build web need neither. Android builds need the Android SDK, a different (much bigger) job.
Disk filling up rm -rf /var/tmp/fb-dl (tarball cache) and rm -rf /var/tmp/pub-cache.

Security notes

Topic Detail
Secrets in this repo None. Nothing here authenticates as anyone.
Download source Google's official Flutter storage (storage.googleapis.com/flutter_infra_release), or — warm cache, default on — this repo's own sha256-pinned sdk-cache release (built by pack.sh; --no-cache disables). Any cache failure falls back to the official archive.
Integrity sha256 checked against releases_linux.json; a mismatch aborts before extraction.
Network at runtime Only the SDK download and pub get against pub.dev.
Telemetry Disabled by the installer.
Privileges sudo is used only for /swapfile, for creating an install root, and for /usr/local/bin symlinks — each is skipped if unavailable, and the default root (/var/tmp/flutter) needs no sudo at all.

Warm cache

setup.sh can install from a warm cache: a zstd archive of an already warmed SDK root (flutter tool snapshot prebuilt), published by pack.sh as a public, sha256-pinned asset of the sdk-cache release, with the digest pinned in cache-manifest.json. Cold installs drop from ~46s to ~25s on a 2-core sandbox (measured). Content is official SDK files only — never app code, never credentials; any sha/version mismatch falls back to the official Google archive. Repack per Flutter version:

bash setup.sh --root /var/tmp/flutter          # install + warm once
GH_TOKEN=... bash pack.sh                       # pack + upload the asset

Layout

flutter-bootstrap/
├── README.md                 ← you are here; agents read this
├── setup.sh                  ← the installer (idempotent, sha256-verified)
├── pack.sh                   ← builds/publishes the warm SDK cache release
├── env.sh                    ← source-able PATH/PUB_CACHE + fb_* helpers
├── NEXT_TIME_BANGLA.md       ← বাংলা cheat sheet + troubleshooting
└── .github/workflows/self-test.yml   ← CI: proves setup.sh works on a clean runner

About

[15/16 · Flutter Studio] ⚡ Give any fresh AI-agent sandbox a working Flutter SDK in ~40s — zero-secret, idempotent, sha256-verified.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages