Skip to content

Commit 6d7e72e

Browse files
mishushakovclaudedjeebus
authored
feat: add Volume CRUD operations to SDKs (#1126)
Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: Joe Lombrozo <joe.lombrozo@e2b.dev>
1 parent 4bee8c5 commit 6d7e72e

71 files changed

Lines changed: 10255 additions & 718 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/shiny-wasps-find.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@e2b/python-sdk': minor
3+
'e2b': minor
4+
---
5+
6+
added volumes support to the SDKs

packages/js-sdk/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
"example": "tsx example.mts",
3030
"test": "vitest run",
3131
"generate": "npm-run-all generate:* && pnpm run format",
32-
"generate:api": "python ./../../spec/remove_extra_tags.py sandboxes snapshots templates tags auth && openapi-typescript ../../spec/openapi_generated.yml -x api_key --array-length --alphabetize --default-non-nullable false --output src/api/schema.gen.ts",
32+
"generate:api": "python ./../../spec/remove_extra_tags.py sandboxes snapshots templates tags auth volumes && openapi-typescript ../../spec/openapi_generated.yml -x api_key --array-length --alphabetize --default-non-nullable false --output src/api/schema.gen.ts",
3333
"generate:envd": "cd ../../spec/envd && buf generate --template buf-js.gen.yaml\n",
3434
"generate:envd-api": "openapi-typescript ../../spec/envd/envd.yaml -x api_key --array-length --alphabetize --output src/envd/schema.gen.ts",
35+
"generate:volume-api": "openapi-typescript ../../spec/openapi-volumecontent.yml -x api_key --array-length --alphabetize --output src/volume/schema.gen.ts",
3536
"generate:mcp": "json2ts -i ./../../spec/mcp-server.json -o src/sandbox/mcp.d.ts --unreachableDefinitions --style.singleQuote --no-style.semi",
3637
"check-deps": "knip",
3738
"pretest": "npx playwright install --with-deps chromium",
@@ -56,7 +57,8 @@
5657
"eslint": "^8.57.1",
5758
"json-schema-to-typescript": "^15.0.4",
5859
"knip": "^5.43.6",
59-
"msw": "^2.12.3",
60+
"msw": "^2.12.10",
61+
"npm-check-updates": "^16.14.20",
6062
"npm-run-all": "^4.1.5",
6163
"openapi-typescript": "^7.9.1",
6264
"playwright": "^1.55.1",

packages/js-sdk/src/api/schema.gen.ts

Lines changed: 154 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/js-sdk/src/errors.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,15 @@ export class FileUploadError extends BuildError {
162162
this.name = 'FileUploadError'
163163
}
164164
}
165+
166+
/**
167+
* Base class for all volume errors.
168+
*
169+
* Thrown when general volume errors occur.
170+
*/
171+
export class VolumeError extends Error {
172+
constructor(message: string) {
173+
super(message)
174+
this.name = 'VolumeError'
175+
}
176+
}

packages/js-sdk/src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export {
1818
RateLimitError,
1919
BuildError,
2020
FileUploadError,
21+
VolumeError,
2122
} from './errors'
2223
export type { Logger } from './logs'
2324

@@ -90,6 +91,17 @@ export type {
9091
GitStatus,
9192
} from './sandbox/git'
9293

94+
export { Volume, VolumeFileType } from './volume'
95+
export type {
96+
VolumeInfo,
97+
VolumeAndToken,
98+
VolumeEntryStat,
99+
VolumeMetadataOptions,
100+
VolumeWriteOptions,
101+
VolumeApiOpts,
102+
VolumeConnectionConfig,
103+
} from './volume'
104+
93105
export { Sandbox }
94106
import { Sandbox } from './sandbox'
95107

packages/js-sdk/src/sandbox/sandboxApi.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { compareVersions } from 'compare-versions'
88
import { SandboxNotFoundError, TemplateError } from '../errors'
99
import { timeoutToSeconds } from '../utils'
10+
import type { Volume } from '../volume'
1011
import type { McpServer as BaseMcpServer } from './mcp'
1112

1213
/**
@@ -156,6 +157,16 @@ export interface SandboxOpts extends ConnectionOpts {
156157
*/
157158
network?: SandboxNetworkOpts
158159

160+
/**
161+
* Volume mounts for the sandbox.
162+
*
163+
* The keys are mount paths inside the sandbox and the values are either
164+
* a `Volume` instance or a string representing the volume name.
165+
*
166+
* @default undefined
167+
*/
168+
volumeMounts?: Record<string, Volume | string>
169+
159170
/**
160171
* Sandbox URL. Used for local development
161172
*/
@@ -337,6 +348,11 @@ export interface SandboxInfo {
337348
* Sandbox lifecycle configuration.
338349
*/
339350
lifecycle?: SandboxInfoLifecycle
351+
352+
/**
353+
* Volume mounts for the sandbox.
354+
*/
355+
volumeMounts?: Array<{ name: string; path: string }>
340356
}
341357

342358
/**
@@ -602,6 +618,7 @@ export class SandboxApi {
602618
}
603619
: undefined,
604620
sandboxDomain: res.data.domain || undefined,
621+
volumeMounts: res.data.volumeMounts ?? [],
605622
}
606623
}
607624

@@ -775,6 +792,15 @@ export class SandboxApi {
775792
: {}),
776793
}
777794

795+
if (opts?.volumeMounts) {
796+
body.volumeMounts = Object.entries(opts.volumeMounts).map(
797+
([mountPath, vol]) => ({
798+
name: typeof vol === 'string' ? vol : vol.name,
799+
path: mountPath,
800+
})
801+
)
802+
}
803+
778804
const res = await client.api.POST('/sandboxes', {
779805
body,
780806
signal: config.getSignal(opts?.requestTimeoutMs),
@@ -959,6 +985,7 @@ export class SandboxPaginator extends BasePaginator<SandboxInfo> {
959985
cpuCount: sandbox.cpuCount,
960986
memoryMB: sandbox.memoryMB,
961987
envdVersion: sandbox.envdVersion,
988+
volumeMounts: sandbox.volumeMounts ?? [],
962989
})
963990
)
964991
}

0 commit comments

Comments
 (0)