Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Improve cache hit consistency across environments (#1010)
Mish Ushakov978fbed96f48
diff --git a/.changeset/sixty-mails-cheat.md b/.changeset/sixty-mails-cheat.mdnew file mode 100644index 000000000..fdfe0b3a0--- /dev/null+++ b/.changeset/sixty-mails-cheat.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': patch+'e2b': patch+---++improve cache hit consistencydiff --git a/packages/js-sdk/src/template/utils.ts b/packages/js-sdk/src/template/utils.tsindex b2a82e6a3..3bd0e047a 100644--- a/packages/js-sdk/src/template/utils.ts+++ b/packages/js-sdk/src/template/utils.ts@@ -71,7 +71,8 @@ export async function getAllFilesForFilesHash(/*** Calculate a hash of files being copied to detect changes for cache invalidation.- * The hash includes file content, metadata (mode, uid, gid, size, mtime), and relative paths.+ * The hash includes file content, metadata (mode, size), and relative paths.+ * Note: uid, gid, and mtime are excluded to ensure stable hashes across environments.** @param src Source path pattern for files to copy* @param dest Destination path where files will be copied@@ -106,13 +107,11 @@ export async function calculateFilesHash(throw error}- // Hash stats+ // Hash stats - only include stable metadata (mode, size)+ // Exclude uid, gid, and mtime to ensure consistent hashes across environmentsconst hashStats = (stats: fs.Stats) => {hash.update(stats.mode.toString())- hash.update(stats.uid.toString())- hash.update(stats.gid.toString())hash.update(stats.size.toString())- hash.update(stats.mtimeMs.toString())}// Process files recursivelydiff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.tsindex 0e952a3ad..9d509b607 100644--- a/packages/js-sdk/tests/setup.ts+++ b/packages/js-sdk/tests/setup.ts@@ -12,21 +12,21 @@ interface SandboxFixture {interface BuildTemplateFixture {buildTemplate: (template: TemplateClass,- skipCache?: boolean,+ options?: { skipCache?: boolean },onBuildLogs?: (logEntry: LogEntry) => void) => Promise<void>}function buildTemplate(template: TemplateClass,- skipCache?: boolean,+ options?: { skipCache?: boolean },onBuildLogs?: (logEntry: LogEntry) => void) {return Template.build(template, {alias: `e2b-test-${randomUUID()}`,cpuCount: 1,memoryMB: 1024,- skipCache: skipCache,+ skipCache: options?.skipCache,onBuildLogs: onBuildLogs,})}diff --git a/packages/js-sdk/tests/template/build.test.ts b/packages/js-sdk/tests/template/build.test.tsindex 6a661227d..dfeb3e084 100644--- a/packages/js-sdk/tests/template/build.test.ts+++ b/packages/js-sdk/tests/template/build.test.ts@@ -35,12 +35,13 @@ buildTemplateTest('build template', async ({ buildTemplate }) => {.setWorkdir('/app').setStartCmd('echo "Hello, world!"', waitForTimeout(10_000))- await buildTemplate(template, undefined, defaultBuildLogger())+ await buildTemplate(template, { skipCache: true }, defaultBuildLogger())})buildTemplateTest('build template with symlinks', async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().copy('folder/*', 'folder', { forceUpload: true }).runCmd('cat folder/symlink.txt')@@ -52,6 +53,7 @@ buildTemplateTest(async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().copy('folder/symlink.txt', 'folder/symlink.txt', {forceUpload: true,resolveSymlinks: true,diff --git a/packages/js-sdk/tests/template/methods/aptInstall.test.ts b/packages/js-sdk/tests/template/methods/aptInstall.test.tsindex 76b7a9d3c..42c401d7c 100644--- a/packages/js-sdk/tests/template/methods/aptInstall.test.ts+++ b/packages/js-sdk/tests/template/methods/aptInstall.test.ts@@ -2,7 +2,10 @@ import { Template } from '../../../src'import { buildTemplateTest } from '../../setup'buildTemplateTest('apt install', async ({ buildTemplate }) => {- const template = Template().fromImage('ubuntu:24.04').aptInstall(['vim'])+ const template = Template()+ .fromImage('ubuntu:24.04')+ .skipCache()+ .aptInstall(['vim'])await buildTemplate(template)})@@ -12,6 +15,7 @@ buildTemplateTest(async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:24.04')+ .skipCache().aptInstall(['vim'], { noInstallRecommends: true })await buildTemplate(template)diff --git a/packages/js-sdk/tests/template/methods/bunInstall.test.ts b/packages/js-sdk/tests/template/methods/bunInstall.test.tsindex 3c9e15d99..6630784a6 100644--- a/packages/js-sdk/tests/template/methods/bunInstall.test.ts+++ b/packages/js-sdk/tests/template/methods/bunInstall.test.ts@@ -4,6 +4,7 @@ import { buildTemplateTest } from '../../setup'buildTemplateTest('bun install', async ({ buildTemplate }) => {const template = Template().fromBunImage('1.3')+ .skipCache().bunInstall(['lodash', 'axios'])await buildTemplate(template)@@ -12,6 +13,7 @@ buildTemplateTest('bun install', async ({ buildTemplate }) => {buildTemplateTest('bun install global', async ({ buildTemplate }) => {const template = Template().fromBunImage('1.3')+ .skipCache().bunInstall(['tsx'], { g: true })await buildTemplate(template)@@ -20,6 +22,7 @@ buildTemplateTest('bun install global', async ({ buildTemplate }) => {buildTemplateTest('bun install dev', async ({ buildTemplate }) => {const template = Template().fromBunImage('1.3')+ .skipCache().bunInstall(['typescript'], { dev: true })await buildTemplate(template)diff --git a/packages/js-sdk/tests/template/methods/fromMethods.test.ts b/packages/js-sdk/tests/template/methods/fromMethods.test.tsindex a6cb81d7c..63161a1cc 100644--- a/packages/js-sdk/tests/template/methods/fromMethods.test.ts+++ b/packages/js-sdk/tests/template/methods/fromMethods.test.ts@@ -21,67 +21,67 @@ afterAll(async () => {buildTemplateTest('fromBaseImage', async ({ buildTemplate }) => {const template = Template().fromBaseImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromDebianImage', async ({ buildTemplate }) => {const template = Template().fromDebianImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromDebianImage with variant', async ({ buildTemplate }) => {const template = Template().fromDebianImage('bookworm')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromUbuntuImage', async ({ buildTemplate }) => {const template = Template().fromUbuntuImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromUbuntuImage with variant', async ({ buildTemplate }) => {const template = Template().fromUbuntuImage('24.04')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromPythonImage', async ({ buildTemplate }) => {const template = Template().fromPythonImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromPythonImage with variant', async ({ buildTemplate }) => {const template = Template().fromPythonImage('3.12')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromNodeImage', async ({ buildTemplate }) => {const template = Template().fromNodeImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromNodeImage with variant', async ({ buildTemplate }) => {const template = Template().fromNodeImage('24')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromBunImage', async ({ buildTemplate }) => {const template = Template().fromBunImage()- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromBunImage with variant', async ({ buildTemplate }) => {const template = Template().fromBunImage('1.3')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromImage', async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromTemplate', async ({ buildTemplate }) => {const template = Template().fromTemplate('base')- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})buildTemplateTest('fromDockerfile', async ({ buildTemplate }) => {@@ -91,5 +91,5 @@ COPY package.json .RUN npm install`const template = Template({ fileContextPath }).fromDockerfile(dockerfile)- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })})diff --git a/packages/js-sdk/tests/template/methods/makeSymlink.test.ts b/packages/js-sdk/tests/template/methods/makeSymlink.test.tsindex 3748ae0d9..ccc666148 100644--- a/packages/js-sdk/tests/template/methods/makeSymlink.test.ts+++ b/packages/js-sdk/tests/template/methods/makeSymlink.test.ts@@ -4,6 +4,7 @@ import { buildTemplateTest } from '../../setup'buildTemplateTest('make symlink', async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().makeSymlink('.bashrc', '.bashrc.local').runCmd('test "$(readlink .bashrc.local)" = ".bashrc"')@@ -13,6 +14,7 @@ buildTemplateTest('make symlink', async ({ buildTemplate }) => {buildTemplateTest('make symlink (force)', async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().makeSymlink('.bashrc', '.bashrc.local').makeSymlink('.bashrc', '.bashrc.local', { force: true }) // Overwrite existing symlink.runCmd('test "$(readlink .bashrc.local)" = ".bashrc"')diff --git a/packages/js-sdk/tests/template/methods/npmInstall.test.ts b/packages/js-sdk/tests/template/methods/npmInstall.test.tsindex fe043dd4e..1ab14227e 100644--- a/packages/js-sdk/tests/template/methods/npmInstall.test.ts+++ b/packages/js-sdk/tests/template/methods/npmInstall.test.ts@@ -4,6 +4,7 @@ import { buildTemplateTest } from '../../setup'buildTemplateTest('npm install', async ({ buildTemplate }) => {const template = Template().fromNodeImage('24')+ .skipCache().npmInstall(['lodash', 'axios'])await buildTemplate(template)@@ -12,6 +13,7 @@ buildTemplateTest('npm install', async ({ buildTemplate }) => {buildTemplateTest('npm install global', async ({ buildTemplate }) => {const template = Template().fromNodeImage('24')+ .skipCache().npmInstall(['tsx'], { g: true })await buildTemplate(template)@@ -20,6 +22,7 @@ buildTemplateTest('npm install global', async ({ buildTemplate }) => {buildTemplateTest('npm install dev', async ({ buildTemplate }) => {const template = Template().fromNodeImage('24')+ .skipCache().npmInstall(['typescript'], { dev: true })await buildTemplate(template)diff --git a/packages/js-sdk/tests/template/methods/pipInstall.test.ts b/packages/js-sdk/tests/template/methods/pipInstall.test.tsindex 074c66ef4..1d20c3774 100644--- a/packages/js-sdk/tests/template/methods/pipInstall.test.ts+++ b/packages/js-sdk/tests/template/methods/pipInstall.test.ts@@ -4,6 +4,7 @@ import { buildTemplateTest } from '../../setup'buildTemplateTest('pip install', async ({ buildTemplate }) => {const template = Template().fromPythonImage('3.13.7-trixie')+ .skipCache().pipInstall(['six', 'pyyaml'])await buildTemplate(template)@@ -12,6 +13,7 @@ buildTemplateTest('pip install', async ({ buildTemplate }) => {buildTemplateTest('pip install (user)', async ({ buildTemplate }) => {const template = Template().fromPythonImage('3.13.7-trixie')+ .skipCache().pipInstall(['six', 'pyyaml'], { g: false })await buildTemplate(template)diff --git a/packages/js-sdk/tests/template/methods/runCmd.test.ts b/packages/js-sdk/tests/template/methods/runCmd.test.tsindex ca4cdc002..340a226a7 100644--- a/packages/js-sdk/tests/template/methods/runCmd.test.ts+++ b/packages/js-sdk/tests/template/methods/runCmd.test.ts@@ -3,7 +3,10 @@ import { Template } from '../../../src'import { buildTemplateTest } from '../../setup'buildTemplateTest('run command', async ({ buildTemplate }) => {- const template = Template().fromImage('ubuntu:22.04').runCmd('ls -l')+ const template = Template()+ .fromImage('ubuntu:22.04')+ .skipCache()+ .runCmd('ls -l')await buildTemplate(template)})@@ -13,6 +16,7 @@ buildTemplateTest(async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().runCmd('test "$(whoami)" = "root"', { user: 'root' })await buildTemplate(template)@@ -24,6 +28,7 @@ buildTemplateTest(async ({ buildTemplate }) => {const template = Template().fromImage('ubuntu:22.04')+ .skipCache().runCmd('whoami', { user: 'root123' })await expect(buildTemplate(template)).rejects.toThrow(diff --git a/packages/js-sdk/tests/template/stacktrace.test.ts b/packages/js-sdk/tests/template/stacktrace.test.tsindex a2da070ce..f70a0ffac 100644--- a/packages/js-sdk/tests/template/stacktrace.test.ts+++ b/packages/js-sdk/tests/template/stacktrace.test.ts@@ -54,34 +54,30 @@ async function expectToThrowAndCheckTrace(}buildTemplateTest('traces on fromImage', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromImage('e2b.dev/this-image-does-not-exist')+ const template = Template().fromImage('e2b.dev/this-image-does-not-exist')await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template, true)+ await buildTemplate(template, { skipCache: true })}, 'fromImage')})buildTemplateTest('traces on fromTemplate', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromTemplate('this-template-does-not-exist')+ const template = Template().fromTemplate('this-template-does-not-exist')await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })}, 'fromTemplate')})buildTemplateTest('traces on fromDockerfile', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromDockerfile(+ const template = Template().fromDockerfile('FROM ubuntu:22.04\nRUN nonexistent')await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template)+ await buildTemplate(template, { skipCache: true })}, 'fromDockerfile')})buildTemplateTest('traces on fromImage registry', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromImage(+ const template = Template().fromImage('registry.example.com/nonexistent:latest',{username: 'test',@@ -89,13 +85,12 @@ buildTemplateTest('traces on fromImage registry', async ({ buildTemplate }) => {})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template, true)+ await buildTemplate(template, { skipCache: true })}, 'fromImage')})buildTemplateTest('traces on fromAWSRegistry', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromAWSRegistry(+ const template = Template().fromAWSRegistry('123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest',{accessKeyId: 'test',@@ -104,20 +99,19 @@ buildTemplateTest('traces on fromAWSRegistry', async ({ buildTemplate }) => {})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template, true)+ await buildTemplate(template, { skipCache: true })}, 'fromAWSRegistry')})buildTemplateTest('traces on fromGCPRegistry', async ({ buildTemplate }) => {- const templateFrom = Template()- const template = templateFrom.fromGCPRegistry(+ const template = Template().fromGCPRegistry('gcr.io/nonexistent-project/nonexistent:latest',{serviceAccountJSON: { type: 'service_account' },})await expectToThrowAndCheckTrace(async () => {- await buildTemplate(template, true)+ await buildTemplate(template, { skipCache: true })}, 'fromGCPRegistry')})@@ -246,7 +240,7 @@ buildTemplateTest('traces on setStartCmd', async ({ buildTemplate }) => {buildTemplateTest('traces on addMcpServer', async () => {// needs mcp-gateway as base template, without it no mcp servers can be addedawait expectToThrowAndCheckTrace(async () => {- Template().fromBaseImage().addMcpServer('exa')+ Template().fromBaseImage().skipCache().addMcpServer('exa')}, 'addMcpServer')})diff --git a/packages/python-sdk/e2b/template/utils.py b/packages/python-sdk/e2b/template/utils.pyindex f0dc3afa9..5c2a239ae 100644--- a/packages/python-sdk/e2b/template/utils.py+++ b/packages/python-sdk/e2b/template/utils.py@@ -88,7 +88,8 @@ def calculate_files_hash("""Calculate a hash of files being copied to detect changes for cache invalidation.- The hash includes file content, metadata (mode, uid, gid, size, mtime), and relative paths.+ The hash includes file content, metadata (mode, size), and relative paths.+ Note: uid, gid, and mtime are excluded to ensure stable hashes across environments.:param src: Source path pattern for files to copy:param dest: Destination path where files will be copied@@ -113,11 +114,10 @@ def calculate_files_hash(raise ValueError(f"No files found in {src_path}").with_traceback(stack_trace)def hash_stats(stat_info: os.stat_result) -> None:+ # Only include stable metadata (mode, size)+ # Exclude uid, gid, and mtime to ensure consistent hashes across environmentshash_obj.update(str(stat_info.st_mode).encode())- hash_obj.update(str(stat_info.st_uid).encode())- hash_obj.update(str(stat_info.st_gid).encode())hash_obj.update(str(stat_info.st_size).encode())- hash_obj.update(str(stat_info.st_mtime).encode())for file in files:# Hash the relative pathdiff --git a/packages/python-sdk/tests/async/template_async/methods/test_apt_install.py b/packages/python-sdk/tests/async/template_async/methods/test_apt_install.pyindex e2d649c4c..4125b8a48 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_apt_install.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_apt_install.py@@ -5,7 +5,9 @@ from e2b import AsyncTemplate@pytest.mark.skip_debug()async def test_apt_install(async_build):- template = AsyncTemplate().from_image("ubuntu:24.04").apt_install(["vim"])+ template = (+ AsyncTemplate().from_image("ubuntu:24.04").skip_cache().apt_install(["vim"])+ )await async_build(template)@@ -15,6 +17,7 @@ async def test_apt_install_no_install_recommends(async_build):template = (AsyncTemplate().from_image("ubuntu:24.04")+ .skip_cache().apt_install(["vim"], no_install_recommends=True))await async_build(template)diff --git a/packages/python-sdk/tests/async/template_async/methods/test_bun_install.py b/packages/python-sdk/tests/async/template_async/methods/test_bun_install.pyindex d525c9fcf..232a70e3c 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_bun_install.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_bun_install.py@@ -5,14 +5,21 @@ from e2b import AsyncTemplate@pytest.mark.skip_debug()async def test_bun_install(async_build):- template = AsyncTemplate().from_bun_image("1.3").bun_install(["lodash", "axios"])+ template = (+ AsyncTemplate()+ .from_bun_image("1.3")+ .skip_cache()+ .bun_install(["lodash", "axios"])+ )await async_build(template)@pytest.mark.skip_debug()async def test_bun_install_global(async_build):- template = AsyncTemplate().from_bun_image("1.3").bun_install(["tsx"], g=True)+ template = (+ AsyncTemplate().from_bun_image("1.3").skip_cache().bun_install(["tsx"], g=True)+ )await async_build(template)@@ -20,7 +27,10 @@ async def test_bun_install_global(async_build):@pytest.mark.skip_debug()async def test_bun_install_dev(async_build):template = (- AsyncTemplate().from_bun_image("1.3").bun_install(["typescript"], dev=True)+ AsyncTemplate()+ .from_bun_image("1.3")+ .skip_cache()+ .bun_install(["typescript"], dev=True))await async_build(template)diff --git a/packages/python-sdk/tests/async/template_async/methods/test_from_methods.py b/packages/python-sdk/tests/async/template_async/methods/test_from_methods.pyindex 85370913b..98cbf4fa7 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_from_methods.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_from_methods.py@@ -25,79 +25,79 @@ def setup_dockerfile_context():@pytest.mark.skip_debug()async def test_from_base_image(async_build):template = AsyncTemplate().from_base_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_debian_image(async_build):template = AsyncTemplate().from_debian_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_debian_image_with_variant(async_build):template = AsyncTemplate().from_debian_image("bookworm")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_ubuntu_image(async_build):template = AsyncTemplate().from_ubuntu_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_ubuntu_image_with_variant(async_build):template = AsyncTemplate().from_ubuntu_image("24.04")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_python_image(async_build):template = AsyncTemplate().from_python_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_python_image_with_variant(async_build):template = AsyncTemplate().from_python_image("3.12")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_node_image(async_build):template = AsyncTemplate().from_node_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_bun_image(async_build):template = AsyncTemplate().from_bun_image()- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_bun_image_with_variant(async_build):template = AsyncTemplate().from_bun_image("1.3")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_node_image_with_variant(async_build):template = AsyncTemplate().from_node_image("24")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_image(async_build):template = AsyncTemplate().from_image("ubuntu:22.04")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()async def test_from_template(async_build):template = AsyncTemplate().from_template("base")- await async_build(template)+ await async_build(template, skip_cache=True)@pytest.mark.skip_debug()@@ -110,4 +110,4 @@ RUN npm install"""template = AsyncTemplate(file_context_path=setup_dockerfile_context).from_dockerfile(dockerfile)- await async_build(template)+ await async_build(template, skip_cache=True)diff --git a/packages/python-sdk/tests/async/template_async/methods/test_make_symlink.py b/packages/python-sdk/tests/async/template_async/methods/test_make_symlink.pyindex 4ffc9670f..aee4a453a 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_make_symlink.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_make_symlink.py@@ -8,6 +8,7 @@ async def test_make_symlink(async_build):template = (AsyncTemplate().from_image("ubuntu:22.04")+ .skip_cache().make_symlink(".bashrc", ".bashrc.local").run_cmd('test "$(readlink .bashrc.local)" = ".bashrc"'))@@ -20,6 +21,7 @@ async def test_make_symlink_force(async_build):template = (AsyncTemplate().from_image("ubuntu:22.04")+ .skip_cache().make_symlink(".bashrc", ".bashrc.local").make_symlink(".bashrc", ".bashrc.local", force=Truediff --git a/packages/python-sdk/tests/async/template_async/methods/test_npm_install.py b/packages/python-sdk/tests/async/template_async/methods/test_npm_install.pyindex 00ce39302..bac27cfc9 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_npm_install.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_npm_install.py@@ -5,14 +5,21 @@ from e2b import AsyncTemplate@pytest.mark.skip_debug()async def test_npm_install(async_build):- template = AsyncTemplate().from_node_image("24").npm_install(["lodash", "axios"])+ template = (+ AsyncTemplate()+ .from_node_image("24")+ .skip_cache()+ .npm_install(["lodash", "axios"])+ )await async_build(template)@pytest.mark.skip_debug()async def test_npm_install_global(async_build):- template = AsyncTemplate().from_node_image("24").npm_install(["tsx"], g=True)+ template = (+ AsyncTemplate().from_node_image("24").skip_cache().npm_install(["tsx"], g=True)+ )await async_build(template)@@ -20,7 +27,10 @@ async def test_npm_install_global(async_build):@pytest.mark.skip_debug()async def test_npm_install_dev(async_build):template = (- AsyncTemplate().from_node_image("24").npm_install(["typescript"], dev=True)+ AsyncTemplate()+ .from_node_image("24")+ .skip_cache()+ .npm_install(["typescript"], dev=True))await async_build(template)diff --git a/packages/python-sdk/tests/async/template_async/methods/test_pip_install.py b/packages/python-sdk/tests/async/template_async/methods/test_pip_install.pyindex 78db16253..dc047ecc7 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_pip_install.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_pip_install.py@@ -8,6 +8,7 @@ async def test_pip_install(async_build):template = (AsyncTemplate().from_python_image("3.13.7-trixie")+ .skip_cache().pip_install(["six", "pyyaml"]))@@ -19,6 +20,7 @@ async def test_pip_install_user(async_build):template = (AsyncTemplate().from_python_image("3.13.7-trixie")+ .skip_cache().pip_install(["six", "pyyaml"], g=False))diff --git a/packages/python-sdk/tests/async/template_async/methods/test_run_cmd.py b/packages/python-sdk/tests/async/template_async/methods/test_run_cmd.pyindex d17b4e915..6f29096ab 100644--- a/packages/python-sdk/tests/async/template_async/methods/test_run_cmd.py+++ b/packages/python-sdk/tests/async/template_async/methods/test_run_cmd.py@@ -5,7 +5,7 @@ from e2b import AsyncTemplate@pytest.mark.skip_debug()async def test_run_command(async_build):- template = AsyncTemplate().from_image("ubuntu:22.04").run_cmd("ls -l")+ template = AsyncTemplate().from_image("ubuntu:22.04").skip_cache().run_cmd("ls -l")await async_build(template)@@ -15,6 +15,7 @@ async def test_run_command_as_different_user(async_build):template = (AsyncTemplate().from_image("ubuntu:22.04")+ .skip_cache().run_cmd('test "$(whoami)" = "root"', user="root"))@@ -24,7 +25,10 @@ async def test_run_command_as_different_user(async_build):@pytest.mark.skip_debug()async def test_run_command_as_user_that_does_not_exist(async_build):template = (- AsyncTemplate().from_image("ubuntu:22.04").run_cmd("whoami", user="root123")+ AsyncTemplate()+ .from_image("ubuntu:22.04")+ .skip_cache()+ .run_cmd("whoami", user="root123"))with pytest.raises(Exception) as exc_info:diff --git a/packages/python-sdk/tests/async/template_async/test_build.py b/packages/python-sdk/tests/async/template_async/test_build.pyindex 781321fa6..00814d2f2 100644--- a/packages/python-sdk/tests/async/template_async/test_build.py+++ b/packages/python-sdk/tests/async/template_async/test_build.py@@ -51,7 +51,7 @@ async def test_build_template(async_build, setup_test_folder):.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)))- await async_build(template, skip_cache=False, on_build_logs=default_build_logger())+ await async_build(template, skip_cache=True, on_build_logs=default_build_logger())@pytest.mark.skip_debug()@@ -59,6 +59,7 @@ async def test_build_template_with_symlinks(async_build, setup_test_folder):template = (AsyncTemplate(file_context_path=setup_test_folder).from_image("ubuntu:22.04")+ .skip_cache().copy("folder/*", "folder", force_upload=True).run_cmd("cat folder/symlink.txt"))@@ -71,6 +72,7 @@ async def test_build_template_with_resolve_symlinks(async_build, setup_test_foldtemplate = (AsyncTemplate(file_context_path=setup_test_folder).from_image("ubuntu:22.04")+ .skip_cache().copy("folder/symlink.txt","folder/symlink.txt",diff --git a/packages/python-sdk/tests/async/template_async/test_stacktrace.py b/packages/python-sdk/tests/async/template_async/test_stacktrace.pyindex 1fd9c0740..ba5813594 100644--- a/packages/python-sdk/tests/async/template_async/test_stacktrace.py+++ b/packages/python-sdk/tests/async/template_async/test_stacktrace.py@@ -29,64 +29,63 @@ async def _expect_to_throw_and_check_trace(func, expected_method: str):@pytest.mark.skip_debug()async def test_traces_on_from_image(async_build):- template = AsyncTemplate()- template = template.skip_cache().from_image("e2b.dev/this-image-does-not-exist")- await _expect_to_throw_and_check_trace(lambda: async_build(template), "from_image")+ template = AsyncTemplate().from_image("e2b.dev/this-image-does-not-exist")+ await _expect_to_throw_and_check_trace(+ lambda: async_build(template, skip_cache=True), "from_image"+ )@pytest.mark.skip_debug()async def test_traces_on_from_template(async_build):template = AsyncTemplate().from_template("this-template-does-not-exist")await _expect_to_throw_and_check_trace(- lambda: async_build(template), "from_template"+ lambda: async_build(template, skip_cache=True), "from_template")@pytest.mark.skip_debug()async def test_traces_on_from_dockerfile(async_build):- template = AsyncTemplate()- template = template.from_dockerfile("FROM ubuntu:22.04\nRUN nonexistent")+ template = AsyncTemplate().from_dockerfile("FROM ubuntu:22.04\nRUN nonexistent")await _expect_to_throw_and_check_trace(- lambda: async_build(template), "from_dockerfile"+ lambda: async_build(template, skip_cache=True), "from_dockerfile")@pytest.mark.skip_debug()async def test_traces_on_from_image_registry(async_build):- template = AsyncTemplate()- template = template.skip_cache().from_image(+ template = AsyncTemplate().from_image("registry.example.com/nonexistent:latest",username="test",password="test",)- await _expect_to_throw_and_check_trace(lambda: async_build(template), "from_image")+ await _expect_to_throw_and_check_trace(+ lambda: async_build(template, skip_cache=True), "from_image"+ )@pytest.mark.skip_debug()async def test_traces_on_from_aws_registry(async_build):- template = AsyncTemplate()- template = template.skip_cache().from_aws_registry(+ template = AsyncTemplate().from_aws_registry("123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",access_key_id="test",secret_access_key="test",region="us-east-1",)await _expect_to_throw_and_check_trace(- lambda: async_build(template), "from_aws_registry"+ lambda: async_build(template, skip_cache=True), "from_aws_registry")@pytest.mark.skip_debug()async def test_traces_on_from_gcp_registry(async_build):- template = AsyncTemplate()- template = template.skip_cache().from_gcp_registry(+ template = AsyncTemplate().from_gcp_registry("gcr.io/nonexistent-project/nonexistent:latest",service_account_json={"type": "service_account",},)await _expect_to_throw_and_check_trace(- lambda: async_build(template), "from_gcp_registry"+ lambda: async_build(template, skip_cache=True), "from_gcp_registry")@@ -214,7 +213,7 @@ async def test_traces_on_start_cmd(async_build):async def test_traces_on_add_mcp_server():# needs mcp-gateway as base template, without it no mcp servers can be addedawait _expect_to_throw_and_check_trace(- lambda: AsyncTemplate().from_base_image().add_mcp_server("exa"),+ lambda: AsyncTemplate().from_base_image().skip_cache().add_mcp_server("exa"),"add_mcp_server",)diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_apt_install.py b/packages/python-sdk/tests/sync/template_sync/methods/test_apt_install.pyindex 5db4e7cbf..d10dc96e4 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_apt_install.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_apt_install.py@@ -5,7 +5,7 @@ from e2b import Template@pytest.mark.skip_debug()def test_apt_install(build):- template = Template().from_image("ubuntu:24.04").apt_install(["vim"])+ template = Template().from_image("ubuntu:24.04").skip_cache().apt_install(["vim"])build(template)@@ -15,6 +15,7 @@ def test_apt_install_no_install_recommends(build):template = (Template().from_image("ubuntu:24.04")+ .skip_cache().apt_install(["vim"], no_install_recommends=True))diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_bun_install.py b/packages/python-sdk/tests/sync/template_sync/methods/test_bun_install.pyindex 6c402ab99..4e2a50e83 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_bun_install.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_bun_install.py@@ -5,20 +5,29 @@ from e2b import Template@pytest.mark.skip_debug()def test_bun_install(build):- template = Template().from_bun_image("1.3").bun_install(["lodash", "axios"])+ template = (+ Template().from_bun_image("1.3").skip_cache().bun_install(["lodash", "axios"])+ )build(template)@pytest.mark.skip_debug()def test_bun_install_global(build):- template = Template().from_bun_image("1.3").bun_install(["tsx"], g=True)+ template = (+ Template().from_bun_image("1.3").skip_cache().bun_install(["tsx"], g=True)+ )build(template)@pytest.mark.skip_debug()def test_bun_install_dev(build):- template = Template().from_bun_image("1.3").bun_install(["typescript"], dev=True)+ template = (+ Template()+ .from_bun_image("1.3")+ .skip_cache()+ .bun_install(["typescript"], dev=True)+ )build(template)diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_from_methods.py b/packages/python-sdk/tests/sync/template_sync/methods/test_from_methods.pyindex b89c8a041..4ef27de48 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_from_methods.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_from_methods.py@@ -26,79 +26,79 @@ def setup_dockerfile_context():@pytest.mark.skip_debug()def test_from_base_image(build):template = Template().from_base_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_debian_image(build):template = Template().from_debian_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_debian_image_with_variant(build):template = Template().from_debian_image("bookworm")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_ubuntu_image(build):template = Template().from_ubuntu_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_ubuntu_image_with_variant(build):template = Template().from_ubuntu_image("24.04")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_python_image(build):template = Template().from_python_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_python_image_with_variant(build):template = Template().from_python_image("3.12")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_node_image(build):template = Template().from_node_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_node_image_with_variant(build):template = Template().from_node_image("24")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_bun_image(build):template = Template().from_bun_image()- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_bun_image_with_variant(build):template = Template().from_bun_image("1.3")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_image(build):template = Template().from_image("ubuntu:22.04")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()def test_from_template(build):template = Template().from_template("base")- build(template)+ build(template, skip_cache=True)@pytest.mark.skip_debug()@@ -111,4 +111,4 @@ RUN npm install"""template = Template(file_context_path=setup_dockerfile_context).from_dockerfile(dockerfile)- build(template)+ build(template, skip_cache=True)diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_make_symlink.py b/packages/python-sdk/tests/sync/template_sync/methods/test_make_symlink.pyindex a05a33726..370e1d5a4 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_make_symlink.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_make_symlink.py@@ -8,6 +8,7 @@ def test_make_symlink(build):template = (Template().from_image("ubuntu:22.04")+ .skip_cache().make_symlink(".bashrc", ".bashrc.local").run_cmd('test "$(readlink .bashrc.local)" = ".bashrc"'))@@ -20,6 +21,7 @@ def test_make_symlink_force(build):template = (Template().from_image("ubuntu:22.04")+ .skip_cache().make_symlink(".bashrc", ".bashrc.local").make_symlink(".bashrc", ".bashrc.local", force=Truediff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_npm_install.py b/packages/python-sdk/tests/sync/template_sync/methods/test_npm_install.pyindex f1b285c44..c77bff7e9 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_npm_install.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_npm_install.py@@ -5,20 +5,29 @@ from e2b import Template@pytest.mark.skip_debug()def test_npm_install(build):- template = Template().from_node_image("24").npm_install(["lodash", "axios"])+ template = (+ Template().from_node_image("24").skip_cache().npm_install(["lodash", "axios"])+ )build(template)@pytest.mark.skip_debug()def test_npm_install_global(build):- template = Template().from_node_image("24").npm_install(["tsx"], g=True)+ template = (+ Template().from_node_image("24").skip_cache().npm_install(["tsx"], g=True)+ )build(template)@pytest.mark.skip_debug()def test_npm_install_dev(build):- template = Template().from_node_image("24").npm_install(["typescript"], dev=True)+ template = (+ Template()+ .from_node_image("24")+ .skip_cache()+ .npm_install(["typescript"], dev=True)+ )build(template)diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_pip_install.py b/packages/python-sdk/tests/sync/template_sync/methods/test_pip_install.pyindex e40c80450..23d5f4382 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_pip_install.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_pip_install.py@@ -6,7 +6,10 @@ from e2b import Template@pytest.mark.skip_debug()def test_pip_install(build):template = (- Template().from_python_image("3.13.7-trixie").pip_install(["six", "pyyaml"])+ Template()+ .from_python_image("3.13.7-trixie")+ .skip_cache()+ .pip_install(["six", "pyyaml"]))build(template)@@ -17,6 +20,7 @@ def test_pip_install_user(build):template = (Template().from_python_image("3.13.7-trixie")+ .skip_cache().pip_install(["six", "pyyaml"], g=False))diff --git a/packages/python-sdk/tests/sync/template_sync/methods/test_run_cmd.py b/packages/python-sdk/tests/sync/template_sync/methods/test_run_cmd.pyindex 9238ffe75..211402689 100644--- a/packages/python-sdk/tests/sync/template_sync/methods/test_run_cmd.py+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_run_cmd.py@@ -5,7 +5,7 @@ from e2b import Template@pytest.mark.skip_debug()def test_run_command(build):- template = Template().from_image("ubuntu:22.04").run_cmd("ls -l")+ template = Template().from_image("ubuntu:22.04").skip_cache().run_cmd("ls -l")build(template)@@ -15,6 +15,7 @@ def test_run_command_as_different_user(build):template = (Template().from_image("ubuntu:22.04")+ .skip_cache().run_cmd('test "$(whoami)" = "root"', user="root"))@@ -23,7 +24,12 @@ def test_run_command_as_different_user(build):@pytest.mark.skip_debug()def test_run_command_as_user_that_does_not_exist(build):- template = Template().from_image("ubuntu:22.04").run_cmd("whoami", user="root123")+ template = (+ Template()+ .from_image("ubuntu:22.04")+ .skip_cache()+ .run_cmd("whoami", user="root123")+ )with pytest.raises(Exception) as exc_info:build(template)diff --git a/packages/python-sdk/tests/sync/template_sync/test_build.py b/packages/python-sdk/tests/sync/template_sync/test_build.pyindex 21943f793..085cd5757 100644--- a/packages/python-sdk/tests/sync/template_sync/test_build.py+++ b/packages/python-sdk/tests/sync/template_sync/test_build.py@@ -51,7 +51,7 @@ def test_build_template(build, setup_test_folder):.set_start_cmd("echo 'Hello, world!'", wait_for_timeout(10_000)))- build(template, skip_cache=False, on_build_logs=default_build_logger())+ build(template, skip_cache=True, on_build_logs=default_build_logger())@pytest.mark.skip_debug()@@ -59,6 +59,7 @@ def test_build_template_with_symlinks(build, setup_test_folder):template = (Template(file_context_path=setup_test_folder).from_image("ubuntu:22.04")+ .skip_cache().copy("folder/*", "folder", force_upload=True).run_cmd("cat folder/symlink.txt"))@@ -71,6 +72,7 @@ def test_build_template_with_resolve_symlinks(build, setup_test_folder):template = (Template(file_context_path=setup_test_folder).from_image("ubuntu:22.04")+ .skip_cache().copy("folder/symlink.txt","folder/symlink.txt",diff --git a/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py b/packages/python-sdk/tests/sync/template_sync/test_stacktrace.pyindex 7142c1433..1ad094874 100644--- a/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py+++ b/packages/python-sdk/tests/sync/template_sync/test_stacktrace.py@@ -30,56 +30,68 @@ def _expect_to_throw_and_check_trace(func, expected_method: str):@pytest.mark.skip_debug()def test_traces_on_from_image(build):template = Template()- template = template.skip_cache().from_image("e2b.dev/this-image-does-not-exist")- _expect_to_throw_and_check_trace(lambda: build(template), "from_image")+ template = template.from_image("e2b.dev/this-image-does-not-exist")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_image"+ )@pytest.mark.skip_debug()def test_traces_on_from_template(build):template = Template().from_template("this-template-does-not-exist")- _expect_to_throw_and_check_trace(lambda: build(template), "from_template")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_template"+ )@pytest.mark.skip_debug()def test_traces_on_from_dockerfile(build):template = Template()template = template.from_dockerfile("FROM ubuntu:22.04\nRUN nonexistent")- _expect_to_throw_and_check_trace(lambda: build(template), "from_dockerfile")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_dockerfile"+ )@pytest.mark.skip_debug()def test_traces_on_from_image_registry(build):template = Template()- template = template.skip_cache().from_image(+ template = template.from_image("registry.example.com/nonexistent:latest",username="test",password="test",)- _expect_to_throw_and_check_trace(lambda: build(template), "from_image")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_image"+ )@pytest.mark.skip_debug()def test_traces_on_from_aws_registry(build):template = Template()- template = template.skip_cache().from_aws_registry(+ template = template.from_aws_registry("123456789.dkr.ecr.us-east-1.amazonaws.com/nonexistent:latest",access_key_id="test",secret_access_key="test",region="us-east-1",)- _expect_to_throw_and_check_trace(lambda: build(template), "from_aws_registry")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_aws_registry"+ )@pytest.mark.skip_debug()def test_traces_on_from_gcp_registry(build):template = Template()- template = template.skip_cache().from_gcp_registry(+ template = template.from_gcp_registry("gcr.io/nonexistent-project/nonexistent:latest",service_account_json={"type": "service_account",},)- _expect_to_throw_and_check_trace(lambda: build(template), "from_gcp_registry")+ _expect_to_throw_and_check_trace(+ lambda: build(template, skip_cache=True), "from_gcp_registry"+ )@pytest.mark.skip_debug()@@ -202,7 +214,7 @@ def test_traces_on_set_start_cmd(build):def test_traces_on_add_mcp_server():# needs mcp-gateway as base template, without it no mcp servers can be added_expect_to_throw_and_check_trace(- lambda: Template().from_base_image().add_mcp_server("exa"),+ lambda: Template().from_base_image().skip_cache().add_mcp_server("exa"),"add_mcp_server",)