@@ -209,6 +209,69 @@ export class Sandbox extends SandboxApi {
209209 this . pty = new Pty ( rpcTransport , this . connectionConfig )
210210 }
211211
212+ static get beta ( ) {
213+ return {
214+ /**
215+ * Resume the sandbox.
216+ *
217+ * The **default sandbox timeout of 300 seconds** ({@link Sandbox.defaultSandboxTimeoutMs}) will be used for the resumed sandbox.
218+ * If you pass a custom timeout in the `opts` parameter via {@link SandboxOpts.timeoutMs} property, it will be used instead.
219+ *
220+ * @param sandboxId sandbox ID.
221+ * @param opts connection options.
222+ *
223+ * @returns a running sandbox instance.
224+ */
225+ resume : Sandbox . resumeSandbox . bind ( Sandbox ) ,
226+ /**
227+ * Pause a sandbox by its ID.
228+ *
229+ * @param sandboxId sandbox ID.
230+ * @param opts connection options.
231+ *
232+ * @returns sandbox ID that can be used to resume the sandbox.
233+ */
234+ pause : Sandbox . pauseSandbox . bind ( Sandbox ) ,
235+ }
236+ }
237+
238+ get beta ( ) {
239+ return {
240+ /**
241+ * Resume the sandbox.
242+ *
243+ * The **default sandbox timeout of 300 seconds** ({@link Sandbox.defaultSandboxTimeoutMs}) will be used for the resumed sandbox.
244+ * If you pass a custom timeout in the `opts` parameter via {@link SandboxOpts.timeoutMs} property, it will be used instead.
245+ *
246+ * @param opts connection options.
247+ *
248+ * @returns a running sandbox instance.
249+ */
250+ resume : async ( opts ?: Omit < SandboxOpts , 'metadata' | 'envs' > ) => {
251+ const timeoutMs = opts ?. timeoutMs ?? Sandbox . defaultSandboxTimeoutMs
252+ return await Sandbox . resumeSandbox ( this . sandboxId , timeoutMs , {
253+ ...this . connectionConfig ,
254+ ...opts ,
255+ } )
256+ } ,
257+ /**
258+ * Pause a sandbox by its ID.
259+ *
260+ * @param opts connection options.
261+ *
262+ * @returns sandbox ID that can be used to resume the sandbox.
263+ */
264+ pause : async (
265+ opts ?: Omit < SandboxOpts , 'metadata' | 'envs' | 'timeoutMs' >
266+ ) => {
267+ return await Sandbox . pauseSandbox ( this . sandboxId , {
268+ ...this . connectionConfig ,
269+ ...opts ,
270+ } )
271+ } ,
272+ }
273+ }
274+
212275 /**
213276 * Create a new sandbox from the default `base` sandbox template.
214277 *
@@ -262,14 +325,15 @@ export class Sandbox extends SandboxApi {
262325 sandboxId : 'debug_sandbox_id' ,
263326 ...config ,
264327 } ) as InstanceType < S >
265- } else {
266- const sandbox = await this . createSandbox (
267- template ,
268- sandboxOpts ?. timeoutMs ?? this . defaultSandboxTimeoutMs ,
269- sandboxOpts
270- )
271- return new this ( { ...sandbox , ...config } ) as InstanceType < S >
272328 }
329+
330+ const sandbox = await this . createSandbox (
331+ template ,
332+ sandboxOpts ?. timeoutMs ?? this . defaultSandboxTimeoutMs ,
333+ sandboxOpts
334+ )
335+
336+ return new this ( { ...sandbox , ...config } ) as InstanceType < S >
273337 }
274338
275339 /**
@@ -295,8 +359,14 @@ export class Sandbox extends SandboxApi {
295359 sandboxId : string ,
296360 opts ?: Omit < SandboxOpts , 'metadata' | 'envs' | 'timeoutMs' >
297361 ) : Promise < InstanceType < S > > {
298- const config = new ConnectionConfig ( opts )
299- const info = await this . getInfo ( sandboxId , opts )
362+ const info = await this . getFullInfo ( sandboxId , opts )
363+
364+ const config = new ConnectionConfig ( {
365+ ...opts ,
366+ // We don't want to pass headers to the connection config as they would then be inherited by all requests,
367+ // which can be confusing.
368+ headers : undefined ,
369+ } )
300370
301371 return new this ( {
302372 sandboxId,
@@ -424,7 +494,7 @@ export class Sandbox extends SandboxApi {
424494
425495 if ( ! useSignature && opts . useSignatureExpiration != undefined ) {
426496 throw new Error (
427- 'Signature expiration can be used only when sandbox is created as secured.'
497+ 'Signature expiration can be used only when sandbox is created as secured.'
428498 )
429499 }
430500
@@ -518,7 +588,9 @@ export class Sandbox extends SandboxApi {
518588 *
519589 * @returns List of sandbox metrics containing CPU, memory and disk usage information.
520590 */
521- async getMetrics ( opts ?: Pick < SandboxMetricsOpts , 'start' | 'end' | 'requestTimeoutMs' > ) {
591+ async getMetrics (
592+ opts ?: Pick < SandboxMetricsOpts , 'start' | 'end' | 'requestTimeoutMs' >
593+ ) {
522594 if ( this . envdApi . version ) {
523595 if ( compareVersions ( this . envdApi . version , '0.1.5' ) < 0 ) {
524596 throw new SandboxError (
0 commit comments