Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
fix: npm install and pip install helpers (#923)
Jakub Dobry1c34e5dd0b6d
diff --git a/.changeset/real-suns-protect.md b/.changeset/real-suns-protect.mdnew file mode 100644index 000000000..52fadf4e8--- /dev/null+++ b/.changeset/real-suns-protect.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': patch+'e2b': patch+---++fix npm install and pip install helpersdiff --git a/packages/js-sdk/src/template/index.ts b/packages/js-sdk/src/template/index.tsindex e0dcc1ab7..759f59d6e 100644--- a/packages/js-sdk/src/template/index.ts+++ b/packages/js-sdk/src/template/index.ts@@ -1,4 +1,5 @@import { ApiClient } from '../api'+import { ConnectionConfig } from '../connectionConfig'import { runtime } from '../utils'import {getFileUploadLink,@@ -8,7 +9,9 @@ import {uploadFile,waitForBuildFinish,} from './buildApi'+import { STACK_TRACE_DEPTH } from './consts'import { parseDockerfile } from './dockerfileParser'+import { ReadyCmd } from './readycmd'import {CopyItem,Instruction,@@ -27,9 +30,6 @@ import {readDockerignore,readGCPServiceAccountJSON,} from './utils'-import { ConnectionConfig } from '../connectionConfig'-import { ReadyCmd } from './readycmd'-import { STACK_TRACE_DEPTH } from './consts'export { type TemplateBuilder } from './types'@@ -378,24 +378,27 @@ export class TemplateBaseargs.push('.')}- return this.runInNewStackTraceContext(() => this.runCmd(args))+ return this.runInNewStackTraceContext(() => this.runCmd(args.join(' ')))}- npmInstall(packages?: string | string[], g?: boolean): TemplateBuilder {+ npmInstall(+ packages?: string | string[],+ options?: { g?: boolean }+ ): TemplateBuilder {const args = ['npm', 'install']const packageList = packages? Array.isArray(packages)? packages: [packages]: undefined+ if (options?.g) {+ args.push('-g')+ }if (packageList) {args.push(...packageList)}- if (g) {- args.push('-g')- }- return this.runInNewStackTraceContext(() => this.runCmd(args))+ return this.runInNewStackTraceContext(() => this.runCmd(args.join(' ')))}aptInstall(packages: string | string[]): TemplateBuilder {diff --git a/packages/js-sdk/src/template/types.ts b/packages/js-sdk/src/template/types.tsindex 02467b549..3c7a50ca4 100644--- a/packages/js-sdk/src/template/types.ts+++ b/packages/js-sdk/src/template/types.ts@@ -116,7 +116,10 @@ export interface TemplateBuilder {pipInstall(packages?: string | string[]): TemplateBuilder- npmInstall(packages?: string | string[], g?: boolean): TemplateBuilder+ npmInstall(+ packages?: string | string[],+ options?: { g?: boolean }+ ): TemplateBuilderaptInstall(packages: string | string[]): TemplateBuilderdiff --git a/packages/js-sdk/tests/template/methods/npmInstall.test.ts b/packages/js-sdk/tests/template/methods/npmInstall.test.tsnew file mode 100644index 000000000..42a3fe16c--- /dev/null+++ b/packages/js-sdk/tests/template/methods/npmInstall.test.ts@@ -0,0 +1,21 @@+import { randomUUID } from 'node:crypto'+import { test } from 'vitest'+import { Template } from '../../../src'++test('npm install', { timeout: 180000 }, async () => {+ const template = Template().fromNodeImage('24').npmInstall(['lodash', 'ms'])++ await Template.build(template, {+ alias: randomUUID(),+ })+})++test('npm install global', { timeout: 180000 }, async () => {+ const template = Template()+ .fromNodeImage('24')+ .npmInstall(['lodash', 'ms'], { g: true })++ await Template.build(template, {+ alias: randomUUID(),+ })+})diff --git a/packages/js-sdk/tests/template/methods/pipInstall.test.ts b/packages/js-sdk/tests/template/methods/pipInstall.test.tsnew file mode 100644index 000000000..c3e8fc34f--- /dev/null+++ b/packages/js-sdk/tests/template/methods/pipInstall.test.ts@@ -0,0 +1,13 @@+import { randomUUID } from 'node:crypto'+import { test } from 'vitest'+import { Template } from '../../../src'++test('pip install', { timeout: 180000 }, async () => {+ const template = Template()+ .fromPythonImage('3.13.7-trixie')+ .pipInstall(['six', 'pyyaml'])++ await Template.build(template, {+ alias: randomUUID(),+ })+})diff --git a/packages/python-sdk/e2b/template/main.py b/packages/python-sdk/e2b/template/main.pyindex 0e894b3a7..bc503fc7a 100644--- a/packages/python-sdk/e2b/template/main.py+++ b/packages/python-sdk/e2b/template/main.py@@ -178,10 +178,10 @@ class TemplateBuilder:packages = [packages]args = ["npm", "install"]- if packages:- args.extend(packages)if g:args.append("-g")+ if packages:+ args.extend(packages)return self._template._run_in_new_stack_trace_context(lambda: self.run_cmd(" ".join(args))diff --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.pynew file mode 100644index 000000000..3eb9904e3--- /dev/null+++ b/packages/python-sdk/tests/async/template_async/methods/test_npm_install.py@@ -0,0 +1,26 @@+import pytest+from uuid import uuid4++from e2b import AsyncTemplate++[email protected]_debug()+async def test_npm_install():+ template = AsyncTemplate().from_node_image("24").npm_install(["lodash", "ms"])++ await AsyncTemplate.build(+ template,+ alias=str(uuid4()),+ )++[email protected]_debug()+async def test_npm_install_global():+ template = (+ AsyncTemplate().from_node_image("24").npm_install(["lodash", "ms"], g=True)+ )++ await AsyncTemplate.build(+ template,+ alias=str(uuid4()),+ )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.pynew file mode 100644index 000000000..a9d647c6a--- /dev/null+++ b/packages/python-sdk/tests/async/template_async/methods/test_pip_install.py@@ -0,0 +1,18 @@+import pytest+from uuid import uuid4++from e2b import AsyncTemplate++[email protected]_debug()+async def test_pip_install():+ template = (+ AsyncTemplate()+ .from_python_image("3.13.7-trixie")+ .pip_install(["six", "pyyaml"])+ )++ await AsyncTemplate.build(+ template,+ alias=str(uuid4()),+ )diff --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.pynew file mode 100644index 000000000..37ecd0eeb--- /dev/null+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_npm_install.py@@ -0,0 +1,24 @@+import pytest+from uuid import uuid4++from e2b import Template++[email protected]_debug()+def test_npm_install():+ template = Template().from_node_image("24").npm_install(["lodash", "ms"])++ Template.build(+ template,+ alias=str(uuid4()),+ )++[email protected]_debug()+def test_npm_install_global():+ template = Template().from_node_image("24").npm_install(["lodash", "ms"], g=True)++ Template.build(+ template,+ alias=str(uuid4()),+ )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.pynew file mode 100644index 000000000..553b79785--- /dev/null+++ b/packages/python-sdk/tests/sync/template_sync/methods/test_pip_install.py@@ -0,0 +1,16 @@+import pytest+from uuid import uuid4++from e2b import Template++[email protected]_debug()+def test_pip_install():+ template = (+ Template().from_python_image("3.13.7-trixie").pip_install(["six", "pyyaml"])+ )++ Template.build(+ template,+ alias=str(uuid4()),+ )