| 175 | opts?: SandboxOpts |
| 176 | ): Promise<InstanceType<S>> |
| 177 | static async create<S extends typeof Sandbox>( |
| 178 | this: S, |
| 179 | templateOrOpts?: SandboxOpts | string, |
| 180 | opts?: SandboxOpts |
| 181 | ): Promise<InstanceType<S>> { |
| 182 | const { template, sandboxOpts } = |
| 183 | typeof templateOrOpts === 'string' |
| 184 | ? { template: templateOrOpts, sandboxOpts: opts } |
| 185 | : { template: this.defaultTemplate, sandboxOpts: templateOrOpts } |
| 186 | |
| 187 | // Add DISPLAY environment variable if not already set |
| 188 | const display = opts?.display || ':0' |
| 189 | const sandboxOptsWithDisplay = { |
| 190 | ...sandboxOpts, |
| 191 | envs: { |
| 192 | ...sandboxOpts?.envs, |
| 193 | DISPLAY: display, |
| 194 | }, |
| 195 | } |
| 196 | |
| 197 | const sbx = (await super.create( |
| 198 | template, |
| 199 | sandboxOptsWithDisplay |
| 200 | )) as InstanceType<S> |
| 201 | await sbx._start(display, sandboxOptsWithDisplay) |
| 202 | |
| 203 | return sbx |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * Wait for a command to return a specific result. |