From 0d0d195e848030a762df5f4d32e463699086639c Mon Sep 17 00:00:00 2001 From: Nivesh353 Date: Thu, 25 Jun 2026 14:51:14 +0530 Subject: [PATCH] fix(sandbox): align E2B sandbox with current gitmachine API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sandbox.ts passed `provider: "e2b"` to GitMachine, but current gitmachine expects a pre-built `machine` — so it was undefined and start() crashed. Now construct E2BMachine first and pass it in (+ env/envs key fix, E2B_API_KEY check, fixed /home/user/repo path). Verified end-to-end: --sandbox boots the VM and runs tools inside it. --- src/sandbox.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sandbox.ts b/src/sandbox.ts index 556816d..db2e9ed 100644 --- a/src/sandbox.ts +++ b/src/sandbox.ts @@ -70,25 +70,39 @@ export async function createSandboxContext( ); } - const gitMachine = new gitmachine.GitMachine({ - provider: config.provider, + const apiKey = process.env.E2B_API_KEY; + if (!apiKey) { + throw new Error( + "Sandbox mode requires an E2B API key. Set E2B_API_KEY in your environment.\n" + + "Get one at https://e2b.dev (Dashboard → API Keys).", + ); + } + + // gitmachine splits VM creation (E2BMachine) from git lifecycle (GitMachine): + // build the provider machine first, then hand it to GitMachine. Note the key + // names differ between the two — E2BMachine uses `envs`, GitMachine uses `env`. + const machine = new gitmachine.E2BMachine({ + apiKey, template: config.template, timeout: config.timeout, + envs: config.envs, + }); + + const gitMachine = new gitmachine.GitMachine({ + machine, repository, token, session: config.session, autoCommit: config.autoCommit ?? true, - envs: config.envs, + env: config.envs, }); - // The repo path inside the sandbox is determined by gitmachine after start(). - // Convention: /home/user/ - const repoName = repository.split("/").pop()?.replace(/\.git$/, "") || "repo"; - const repoPath = `/home/user/${repoName}`; + // gitmachine clones into a fixed path inside the VM (/home/user/repo). + const repoPath = "/home/user/repo"; return { gitMachine, - machine: gitMachine.machine, + machine, repoPath, }; }