Create a new sandbox. By default, the sandbox is created from the default `desktop` sandbox template. :param template: Sandbox template name or ID :param resolution: Startup the desktop with custom screen resolution. Defaults to (1024, 768) :param dpi: Sta
(
cls,
template: Optional[str] = None,
resolution: Optional[Tuple[int, int]] = None,
dpi: Optional[int] = None,
display: Optional[str] = None,
timeout: Optional[int] = None,
metadata: Optional[Dict[str, str]] = None,
envs: Optional[Dict[str, str]] = None,
secure: bool = True,
allow_internet_access: bool = True,
**opts: Unpack[ApiParams],
)
| 209 | |
| 210 | @classmethod |
| 211 | def create( |
| 212 | cls, |
| 213 | template: Optional[str] = None, |
| 214 | resolution: Optional[Tuple[int, int]] = None, |
| 215 | dpi: Optional[int] = None, |
| 216 | display: Optional[str] = None, |
| 217 | timeout: Optional[int] = None, |
| 218 | metadata: Optional[Dict[str, str]] = None, |
| 219 | envs: Optional[Dict[str, str]] = None, |
| 220 | secure: bool = True, |
| 221 | allow_internet_access: bool = True, |
| 222 | **opts: Unpack[ApiParams], |
| 223 | ) -> Self: |
| 224 | """ |
| 225 | Create a new sandbox. |
| 226 | |
| 227 | By default, the sandbox is created from the default `desktop` sandbox template. |
| 228 | |
| 229 | |
| 230 | :param template: Sandbox template name or ID |
| 231 | :param resolution: Startup the desktop with custom screen resolution. Defaults to (1024, 768) |
| 232 | :param dpi: Startup the desktop with custom DPI. Defaults to 96 |
| 233 | :param display: Startup the desktop with custom display. Defaults to ":0" |
| 234 | :param timeout: Timeout for the sandbox in **seconds**, default to 300 seconds. The maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users. |
| 235 | :param metadata: Custom metadata for the sandbox |
| 236 | :param envs: Custom environment variables for the sandbox |
| 237 | :param secure: Envd is secured with access token and cannot be used without it |
| 238 | :param allow_internet_access: Allow sandbox to access the internet, defaults to `True`. |
| 239 | |
| 240 | :return: A Sandbox instance for the new sandbox |
| 241 | |
| 242 | Use this method instead of using the constructor to create a new sandbox. |
| 243 | """ |
| 244 | |
| 245 | # Initialize environment variables with DISPLAY |
| 246 | display = display or ":0" |
| 247 | if envs is None: |
| 248 | envs = {} |
| 249 | envs["DISPLAY"] = display |
| 250 | |
| 251 | sbx = super().create( |
| 252 | template=template, |
| 253 | timeout=timeout, |
| 254 | metadata=metadata, |
| 255 | envs=envs, |
| 256 | secure=secure, |
| 257 | allow_internet_access=allow_internet_access, |
| 258 | **opts, |
| 259 | ) |
| 260 | |
| 261 | sbx._display = display |
| 262 | width, height = resolution or (1024, 768) |
| 263 | xvfb_handle = sbx.commands.run( |
| 264 | f"Xvfb {display} -ac -screen 0 {width}x{height}x24" |
| 265 | f" -retro -dpi {dpi or 96} -nolisten tcp -nolisten unix", |
| 266 | background=True, |
| 267 | timeout=0, |
| 268 | ) |