Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<repo-name>
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,
};
}