@@ -30,30 +30,31 @@ type sandboxServiceImpl struct{ client *Client }
3030
3131// SandboxCreateParams are options for creating a Modal Sandbox.
3232type SandboxCreateParams struct {
33- CPU float64 // CPU request in fractional, physical cores.
34- CPULimit float64 // Hard limit in fractional, physical CPU cores. Zero means no limit.
35- MemoryMiB int // Memory request in MiB.
36- MemoryLimitMiB int // Hard memory limit in MiB. Zero means no limit.
37- GPU string // GPU reservation for the Sandbox (e.g. "A100", "T4:2", "A100-80GB:4").
38- Timeout time.Duration // Maximum lifetime of the Sandbox. Defaults to 5 minutes. If you pass zero you get the default 5 minutes.
39- IdleTimeout time.Duration // The amount of time that a Sandbox can be idle before being terminated.
40- Workdir string // Working directory of the Sandbox.
41- Command []string // Command to run in the Sandbox on startup.
42- Env map [string ]string // Environment variables to set in the Sandbox.
43- Secrets []* Secret // Secrets to inject into the Sandbox as environment variables.
44- Volumes map [string ]* Volume // Mount points for Volumes.
45- CloudBucketMounts map [string ]* CloudBucketMount // Mount points for cloud buckets.
46- PTY bool // Enable a PTY for the Sandbox.
47- EncryptedPorts []int // List of encrypted ports to tunnel into the Sandbox, with TLS encryption.
48- H2Ports []int // List of encrypted ports to tunnel into the Sandbox, using HTTP/2.
49- UnencryptedPorts []int // List of ports to tunnel into the Sandbox without encryption.
50- BlockNetwork bool // Whether to block all network access from the Sandbox.
51- CIDRAllowlist []string // List of CIDRs the Sandbox is allowed to access. Cannot be used with BlockNetwork.
52- Cloud string // Cloud provider to run the Sandbox on.
53- Regions []string // Region(s) to run the Sandbox on.
54- Verbose bool // Enable verbose logging.
55- Proxy * Proxy // Reference to a Modal Proxy to use in front of this Sandbox.
56- Name string // Optional name for the Sandbox. Unique within an App.
33+ CPU float64 // CPU request in fractional, physical cores.
34+ CPULimit float64 // Hard limit in fractional, physical CPU cores. Zero means no limit.
35+ MemoryMiB int // Memory request in MiB.
36+ MemoryLimitMiB int // Hard memory limit in MiB. Zero means no limit.
37+ GPU string // GPU reservation for the Sandbox (e.g. "A100", "T4:2", "A100-80GB:4").
38+ Timeout time.Duration // Maximum lifetime of the Sandbox. Defaults to 5 minutes. If you pass zero you get the default 5 minutes.
39+ IdleTimeout time.Duration // The amount of time that a Sandbox can be idle before being terminated.
40+ Workdir string // Working directory of the Sandbox.
41+ Command []string // Command to run in the Sandbox on startup.
42+ Env map [string ]string // Environment variables to set in the Sandbox.
43+ Secrets []* Secret // Secrets to inject into the Sandbox as environment variables.
44+ Volumes map [string ]* Volume // Mount points for Volumes.
45+ CloudBucketMounts map [string ]* CloudBucketMount // Mount points for cloud buckets.
46+ PTY bool // Enable a PTY for the Sandbox.
47+ EncryptedPorts []int // List of encrypted ports to tunnel into the Sandbox, with TLS encryption.
48+ H2Ports []int // List of encrypted ports to tunnel into the Sandbox, using HTTP/2.
49+ UnencryptedPorts []int // List of ports to tunnel into the Sandbox without encryption.
50+ BlockNetwork bool // Whether to block all network access from the Sandbox.
51+ CIDRAllowlist []string // List of CIDRs the Sandbox is allowed to access. Cannot be used with BlockNetwork.
52+ Cloud string // Cloud provider to run the Sandbox on.
53+ Regions []string // Region(s) to run the Sandbox on.
54+ Verbose bool // Enable verbose logging.
55+ Proxy * Proxy // Reference to a Modal Proxy to use in front of this Sandbox.
56+ Name string // Optional name for the Sandbox. Unique within an App.
57+ ExperimentalOptions map [string ]any // Experimental options
5758}
5859
5960// buildSandboxCreateRequestProto builds a SandboxCreateRequest proto from options.
@@ -244,26 +245,39 @@ func buildSandboxCreateRequestProto(appID, imageID string, params SandboxCreateP
244245 resourcesBuilder .MemoryMbMax = memoryMbMax
245246 }
246247
248+ // The public interface uses map[string]any so that we can add support for any experimental
249+ // option type in the future. Currently, the proto only supports map[string]bool so we validate
250+ // the input here.
251+ protoExperimentalOptions := map [string ]bool {}
252+ for name , value := range params .ExperimentalOptions {
253+ boolValue , ok := value .(bool )
254+ if ! ok {
255+ return nil , fmt .Errorf ("experimental option '%s' must be a bool, got %T" , name , value )
256+ }
257+ protoExperimentalOptions [name ] = boolValue
258+ }
259+
247260 return pb.SandboxCreateRequest_builder {
248261 AppId : appID ,
249262 Definition : pb.Sandbox_builder {
250- EntrypointArgs : params .Command ,
251- ImageId : imageID ,
252- SecretIds : secretIds ,
253- TimeoutSecs : timeoutSecs ,
254- IdleTimeoutSecs : idleTimeoutSecs ,
255- Workdir : workdir ,
256- NetworkAccess : networkAccess ,
257- Resources : resourcesBuilder .Build (),
258- VolumeMounts : volumeMounts ,
259- CloudBucketMounts : cloudBucketMounts ,
260- PtyInfo : ptyInfo ,
261- OpenPorts : portSpecs ,
262- CloudProviderStr : params .Cloud ,
263- SchedulerPlacement : schedulerPlacement ,
264- Verbose : params .Verbose ,
265- ProxyId : proxyID ,
266- Name : & params .Name ,
263+ EntrypointArgs : params .Command ,
264+ ImageId : imageID ,
265+ SecretIds : secretIds ,
266+ TimeoutSecs : timeoutSecs ,
267+ IdleTimeoutSecs : idleTimeoutSecs ,
268+ Workdir : workdir ,
269+ NetworkAccess : networkAccess ,
270+ Resources : resourcesBuilder .Build (),
271+ VolumeMounts : volumeMounts ,
272+ CloudBucketMounts : cloudBucketMounts ,
273+ PtyInfo : ptyInfo ,
274+ OpenPorts : portSpecs ,
275+ CloudProviderStr : params .Cloud ,
276+ SchedulerPlacement : schedulerPlacement ,
277+ Verbose : params .Verbose ,
278+ ProxyId : proxyID ,
279+ Name : & params .Name ,
280+ ExperimentalOptions : protoExperimentalOptions ,
267281 }.Build (),
268282 }.Build (), nil
269283}
0 commit comments