Skip to content

Instantly share code, notes, and snippets.

@anthonywu
Last active October 23, 2025 22:20
Show Gist options
  • Select an option

  • Save anthonywu/c10ff9ef0a35cfcb58cd4299dee5324c to your computer and use it in GitHub Desktop.

Select an option

Save anthonywu/c10ff9ef0a35cfcb58cd4299dee5324c to your computer and use it in GitHub Desktop.
E2B npm run next app sandbox test
✘ anthonywu@lunar-shadow  ~/workspace/makeme-dev/src/e2b-sandbox-1   e2b-sandbox-starter ±  bun run test-1
$ dotenvx run -f .env.local -- tsx ./test_1.ts
[[email protected]] 📡 radar: off
[[email protected]] injecting env (3) from .env.local
{
exitCode: 0,
error: undefined,
stdout: 'Filesystem Size Used Avail Use% Mounted on\n' +
'/dev/root 24G 4.0G 20G 17% /\n',
stderr: ''
}
{
stdout: [ 'hello world - the sandbox is alive and real work comes next\n' ],
stderr: []
}
Thu Oct 23 22:13:20 UTC 2025
Creating a new Next.js app in /tmp/sandbox-app-1.
Using npm.
Initializing project with template: app-tw
Installing dependencies:
- react
- react-dom
- next
Installing devDependencies:
- typescript
- @types/node
- @types/react
- @types/react-dom
- @tailwindcss/postcss
- tailwindcss
- eslint
- eslint-config-next
/Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/node_modules/e2b/src/envd/rpc.ts:32
return new TimeoutError(
^
TimeoutError: [deadline_exceeded] the operation timed out: This error is likely due to exceeding 'timeoutMs' — the total time a long running request (like command execution or directory watch) can be active. It can be modified by passing 'timeoutMs' when making the request. Use '0' to disable the timeout.
at handleRpcError (/Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/node_modules/e2b/src/envd/rpc.ts:32:16)
at CommandHandle.handleEvents (/Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/node_modules/e2b/src/sandbox/commands/commandHandle.ts:237:29)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async CommandHandle.wait (/Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/node_modules/e2b/src/sandbox/commands/commandHandle.ts:150:5)
at async <anonymous> (/Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/test_1.ts:26:31)
Node.js v22.15.0
Command failed with exit code 1: /Users/anthonywu/workspace/makeme-dev/src/e2b-sandbox-1/node_modules/.bin/tsx ./test_1.ts
error: script "test-1" exited with code 1
{
"type": "module",
"scripts": {
"test-1": "tsx ./test_1.ts"
},
"dependencies": {
"@e2b/code-interpreter": "^2.1.0"
},
"devDependencies": {
"tsx": "^4.20.6"
}
}
import { Sandbox, Template } from "@e2b/code-interpreter";
const template = Template()
.fromBaseImage()
.runCmd("node --version && npm --version && deno --version && python -V") // user
.runCmd("pwd"); // /home/user
const sandbox = await Sandbox.betaCreate({ allowInternetAccess: true, autoPause: true, timeoutMs: 10 * 60 * 1000 });
// only 4G of 24G available on live sandbox?!! escalated to e2b support team
console.log(await sandbox.commands.run("df -h /"));
// Execute Python inside the sandbox
const pyExec = await sandbox.runCode('print("hello world - the sandbox is alive and real work comes next")');
console.log(pyExec.logs);
// process.exit();
await sandbox.commands.run("npm config set update-notifier false && npm config set fund false");
const projectName = "sandbox-app-1";
const workspaceParentDir = "/tmp";
const projectFolder = `${workspaceParentDir}/${projectName}`;
const projectPort = 5000;
// all commands start with pwd /home/user
const projectCheckoutResult = await sandbox.commands.run(
// migrate some of these steps into templates / base images
// create-next-app step: 1.5 minutes on macOS docker
`date && cd ${workspaceParentDir} && CI=true NO_COLOR=1 npx --yes create-next-app@latest ${projectName} --disable-git --typescript --tailwind --app --turbopack --yes && du -sh ${projectName}`,
{
// the first/dependent/setups must be foreground
// otherwise the next commands will run before the setup is done
background: false,
timeoutMs: 5 * 60_000,
onStdout: (outputData) => {
console.log(outputData);
},
onStderr: (errorData) => {
console.error(errorData);
},
},
);
await sandbox.commands.run(`date && cd ${projectFolder} && PORT=${projectPort} npm run dev`, {
background: true,
timeoutMs: 10 * 60_000,
onStdout: (outputData) => {
console.log(outputData);
},
onStderr: (errorData) => {
console.error(errorData);
},
});
// const files = await sbx.files.list("/");
// console.log(files);
const host = sandbox.getHost(projectPort);
const url = `https://${host}`;
console.log("Server started at:", url);
// Fetch data from the server inside the sandbox.
const response = await fetch(url);
const data = await response.text();
console.log("Response from server inside sandbox:", data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment