@@ -61,10 +61,41 @@ var sandboxBoxDetailRender = structured.PropertyList{
6161 },
6262}
6363
64+ func sandboxCreateParams (name string , in * sandboxCreateInput ) (langsmith.SandboxBoxNewParams , error ) {
65+ memBytes , err := parseByteSize (in .Memory )
66+ if err != nil {
67+ return langsmith.SandboxBoxNewParams {}, fmt .Errorf ("invalid --memory: %w" , err )
68+ }
69+
70+ params := langsmith.SandboxBoxNewParams {
71+ Name : langsmith .F (name ),
72+ Vcpus : langsmith .F (int64 (in .VCPUs )),
73+ MemBytes : langsmith .F (memBytes ),
74+ }
75+ if in .SnapshotID != "" {
76+ params .SnapshotID = langsmith .F (in .SnapshotID )
77+ }
78+ if in .RootFS != "" {
79+ rootfsBytes , err := parseByteSize (in .RootFS )
80+ if err != nil {
81+ return langsmith.SandboxBoxNewParams {}, fmt .Errorf ("invalid --rootfs-capacity: %w" , err )
82+ }
83+ params .FsCapacityBytes = langsmith .F (rootfsBytes )
84+ }
85+ if in .ProxyConfig != "" {
86+ pc , err := loadJSONArg (in .ProxyConfig )
87+ if err != nil {
88+ return langsmith.SandboxBoxNewParams {}, fmt .Errorf ("invalid --proxy-config: %w" , err )
89+ }
90+ params .ProxyConfig = langsmith.Raw [langsmith.SandboxBoxNewParamsProxyConfig ](pc )
91+ }
92+ return params , nil
93+ }
94+
6495var sandboxCreateCommand = structured.Command [* sandboxCreateInput ]{
6596 Use : "create <name>" ,
66- Short : "Create a sandbox VM from a snapshot " ,
67- Long : `Create a sandbox VM from a snapshot .
97+ Short : "Create a sandbox VM" ,
98+ Long : `Create a sandbox VM.
6899
69100The --proxy-config flag accepts inline JSON or a file path prefixed with @.
70101The proxy config controls which outbound HTTP requests the sandbox proxy
@@ -92,6 +123,7 @@ Header types: "plaintext" (literal value), "opaque" (encrypted, hidden in API
92123responses), "workspace_secret" (resolved from workspace secrets via {KEY}).
93124
94125Examples:
126+ langsmith sandbox create my-vm
95127 langsmith sandbox create my-vm --snapshot-id <id>
96128 langsmith sandbox create my-vm --snapshot-id <id> --vcpus 4 --memory 1gb
97129 langsmith sandbox create my-vm --snapshot-id <id> --rootfs-capacity 8gb
@@ -102,7 +134,7 @@ Examples:
102134 VCPUs : 2 ,
103135 Memory : "512mb" ,
104136 }
105- cmd .Flags ().StringVar (& in .SnapshotID , "snapshot-id" , in .SnapshotID , "Snapshot ID to boot from (required) " )
137+ cmd .Flags ().StringVar (& in .SnapshotID , "snapshot-id" , in .SnapshotID , "Snapshot ID to boot from" )
106138 cmd .Flags ().IntVar (& in .VCPUs , "vcpus" , in .VCPUs , "Number of vCPUs" )
107139 cmd .Flags ().StringVar (& in .Memory , "memory" , in .Memory , "Memory with unit (e.g. 512mb, 1gb)" )
108140 cmd .Flags ().StringVar (& in .RootFS , "rootfs-capacity" , in .RootFS , "Root filesystem capacity with unit (e.g. 4gb, 8gb)" )
@@ -111,39 +143,15 @@ Examples:
111143 },
112144 Action : func (ctx context.Context , cmd * cobra.Command , in * sandboxCreateInput , args []string ) (any , error ) {
113145 name := args [0 ]
114- if in .SnapshotID == "" {
115- return nil , fmt .Errorf ("--snapshot-id is required" )
116- }
117146
118147 c , err := cmdutil .GetClient (cmd )
119148 if err != nil {
120149 return nil , err
121150 }
122151
123- memBytes , err := parseByteSize ( in . Memory )
152+ params , err := sandboxCreateParams ( name , in )
124153 if err != nil {
125- return nil , fmt .Errorf ("invalid --memory: %w" , err )
126- }
127-
128- params := langsmith.SandboxBoxNewParams {
129- Name : langsmith .F (name ),
130- SnapshotID : langsmith .F (in .SnapshotID ),
131- Vcpus : langsmith .F (int64 (in .VCPUs )),
132- MemBytes : langsmith .F (memBytes ),
133- }
134- if in .RootFS != "" {
135- rootfsBytes , err := parseByteSize (in .RootFS )
136- if err != nil {
137- return nil , fmt .Errorf ("invalid --rootfs-capacity: %w" , err )
138- }
139- params .FsCapacityBytes = langsmith .F (rootfsBytes )
140- }
141- if in .ProxyConfig != "" {
142- pc , err := loadJSONArg (in .ProxyConfig )
143- if err != nil {
144- return nil , fmt .Errorf ("invalid --proxy-config: %w" , err )
145- }
146- params .ProxyConfig = langsmith.Raw [langsmith.SandboxBoxNewParamsProxyConfig ](pc )
154+ return nil , err
147155 }
148156 resp , err := c .SDK .Sandboxes .Boxes .New (ctx , params )
149157 if err != nil {
0 commit comments