@@ -5,8 +5,9 @@ import { timeout } from "../args/timeout";
55import { vcpus } from "../args/vcpus" ;
66import chalk from "chalk" ;
77import { scope } from "../args/scope" ;
8- import { sandboxClient } from "../client" ;
8+ import { sandboxClient , snapshotClient } from "../client" ;
99import { snapshotId } from "../args/snapshot-id" ;
10+ import { sandboxName } from "../args/sandbox-name" ;
1011import ora from "ora" ;
1112import * as Exec from "./exec" ;
1213import { networkPolicyArgs } from "../args/network-policy" ;
@@ -59,6 +60,12 @@ export const args = {
5960 description : "Start the sandbox from a snapshot ID" ,
6061 type : cmd . optional ( snapshotId ) ,
6162 } ) ,
63+ sandboxSnapshot : cmd . option ( {
64+ long : "sandbox-snapshot" ,
65+ description :
66+ "Start the sandbox from another sandbox's current snapshot" ,
67+ type : cmd . optional ( sandboxName ) ,
68+ } ) ,
6269 connect : cmd . flag ( {
6370 long : "connect" ,
6471 description :
@@ -105,6 +112,7 @@ export const create = cmd.command({
105112 vcpus,
106113 silent,
107114 snapshot,
115+ sandboxSnapshot,
108116 connect,
109117 envVars,
110118 tags,
@@ -114,6 +122,15 @@ export const create = cmd.command({
114122 allowedCIDRs,
115123 deniedCIDRs,
116124 } ) {
125+ if ( snapshot && sandboxSnapshot ) {
126+ throw new Error (
127+ [
128+ `Cannot use --snapshot and --sandbox-snapshot together.` ,
129+ `${ chalk . bold ( "hint:" ) } Pick one source for the new sandbox.` ,
130+ ] . join ( "\n" ) ,
131+ ) ;
132+ }
133+
117134 const networkPolicy = buildNetworkPolicy ( {
118135 networkPolicy : networkPolicyMode ,
119136 allowedDomains,
@@ -124,11 +141,20 @@ export const create = cmd.command({
124141 const persistent = ! nonPersistent
125142 const resources = vcpus ? { vcpus } : undefined ;
126143 const tagsObj = Object . keys ( tags ) . length > 0 ? tags : undefined ;
144+ const resolvedSnapshot =
145+ snapshot ??
146+ ( sandboxSnapshot
147+ ? await snapshotClient . fromSandbox ( sandboxSnapshot , {
148+ teamId : scope . team ,
149+ projectId : scope . project ,
150+ token : scope . token ,
151+ } )
152+ : undefined ) ;
127153 const spinner = silent ? undefined : ora ( "Creating sandbox..." ) . start ( ) ;
128- const sandbox = snapshot
154+ const sandbox = resolvedSnapshot
129155 ? await sandboxClient . create ( {
130156 name,
131- source : { type : "snapshot" , snapshotId : snapshot } ,
157+ source : { type : "snapshot" , snapshotId : resolvedSnapshot } ,
132158 teamId : scope . team ,
133159 projectId : scope . project ,
134160 token : scope . token ,
0 commit comments