Add InstaVM environment support#156
Open
mkagenius wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new instavm isolated REPL backend so RLM can run generated Python inside InstaVM microVMs, extending the existing family of cloud sandbox environments alongside Modal, E2B, Daytona, and Prime.
Changes:
- Adds a new
InstaVMREPLenvironment implementation with VM setup, in-VM execution, and host-side LM request brokering. - Registers
instavmas a selectable environment and adds the optional package extra/dependency lock entries. - Documents installation/usage and adds a runnable example for the new environment.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Locks the new instavm optional dependency and extra metadata. |
rlm/environments/instavm_repl.py |
Implements the new InstaVM-backed isolated REPL environment. |
rlm/environments/__init__.py |
Wires instavm into environment lookup and exports. |
pyproject.toml |
Adds the instavm optional dependency extra. |
examples/instavm_repl_example.py |
Demonstrates configuring RLM with the new environment. |
README.md |
Documents InstaVM support and installation steps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| __all__ = [ | ||
| "BaseEnv", | ||
| "IPythonREPL", | ||
| "InstaVMREPL", |
Comment on lines
+373
to
+375
| share = self.vm.shares.create(port=self.BROKER_PORT, is_public=True) | ||
| self.broker_url = share["url"].rstrip("/") | ||
| self.share_id = share.get("share_id") |
Comment on lines
+431
to
+434
| if req_type == "single": | ||
| prompt = req_data.get("prompt") | ||
| request = LMRequest(prompt=prompt, model=model) | ||
| response = send_lm_request(self.lm_handler_address, request) |
Comment on lines
+441
to
+443
| if req_type == "batched": | ||
| prompts = req_data.get("prompts", []) | ||
| responses = send_lm_request_batched(self.lm_handler_address, prompts, model=model) |
Comment on lines
+231
to
+235
| "__name__": "__main__", | ||
| "llm_query": llm_query, | ||
| "llm_query_batched": llm_query_batched, | ||
| "FINAL_VAR": FINAL_VAR, | ||
| }} |
Comment on lines
+184
to
+204
| if os.path.exists(STATE_FILE): | ||
| try: | ||
| with open(STATE_FILE, "rb") as fh: | ||
| return pickle.load(fh) | ||
| except Exception: | ||
| return {{}} | ||
| return {{}} | ||
|
|
||
|
|
||
| def save_state(state): | ||
| clean = {{}} | ||
| for key, value in state.items(): | ||
| if key.startswith("_"): | ||
| continue | ||
| try: | ||
| pickle.dumps(value) | ||
| clean[key] = value | ||
| except Exception: | ||
| continue | ||
| with open(STATE_FILE, "wb") as fh: | ||
| pickle.dump(clean, fh) |
Comment on lines
50
to
+53
| def get_environment( | ||
| environment: Literal["local", "ipython", "modal", "docker", "daytona", "prime", "e2b"], | ||
| environment: Literal[ | ||
| "local", "ipython", "modal", "docker", "daytona", "prime", "e2b", "instavm" | ||
| ], |
InstaVM (https://instavm.io) provides Firecracker microVMs with sub-second cold starts and stateful Python execution. This adds a new InstaVMREPL environment class following the existing isolated-env pattern (e2b/modal/ daytona), so it plugs into RLM via: rlm = RLM( environment="instavm", environment_kwargs={"api_key": ...}, ) Implementation notes: - Uses the same HTTP broker pattern as ModalREPL/E2BREPL for forwarding in-VM llm_query / llm_query_batched calls back to the host LMHandler. - Broker runs entirely on Python stdlib (http.server, pickle) inside the VM; in-VM client uses httpx (preinstalled in InstaVM images) so the setup phase needs zero pip-install steps. - Public broker URL is obtained via vm.shares.create(port=..., is_public=True). - persistent=True raises NotImplementedError (matches E2BREPL/ModalREPL). - Optional dep declared as the 'instavm' extra; lazy-imported only when the environment is actually used so test_imports.py stays happy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0fab680 to
811b914
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an
InstaVMREPLenvironment that runs Python code in InstaVM Firecracker microVMs (sub-second cold starts, stateful Python).Usage
Or via the env var
INSTAVM_API_KEY. Install withpip install -e ".[instavm]".Implementation
Follows the same isolated-env pattern as
E2BREPL/ModalREPL/DaytonaREPL:vm.shares.create(port=..., is_public=True)./pendingrequests to the localLMHandlerand posts responses back to/respond.llm_query/llm_query_batchedusehttpx(preinstalled in InstaVM images).http.server,pickle) — nopip installstep at session setup.persistent=TrueraisesNotImplementedError, mirroringE2BREPL/ModalREPL.instavmextra with lazy import;tests/test_imports.pycontinues to pass without the extra installed.Verification
uv run ruff check --fix .— passesuv run ruff format .— passesuv run pre-commit run --all-files— passes (ruff + ruff format + ty)uv run pytest— 277 passed (only failure is a pre-existingtest_async_completionconfig issue intests/clients/test_gemini.pyunrelated to this change)llm_query, batchedllm_query_batched, andFINAL_VARcross-block lookup all work.History
This is a fresh redo of an unsubmitted draft branch (
feature/instavm-environmenton the same fork) from ~4 months ago. The original branch never made it to a PR; in the meantime upstream rewrote the env base classes and InstaVM's SDK moved0.8.0 → 0.21.0, so this is a clean reimplementation against current upstream conventions rather than a rebase.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com