> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
> Use this file to discover all available pages before exploring further.

# wait

> Wait for waitables to complete and return done and pending lists.

Source: [src/cwsandbox/**init**.py:121](https://github.com/coreweave/cwsandbox-client/blob/v0.22.0/src/cwsandbox/__init__.py#L121)

```python theme={"system"}
wait(waitables: Sequence[Waitable], num_returns: int | None = None, timeout: float | None = None) -> tuple[list[Waitable], list[Waitable]]
```

Wait for waitables to complete, and return a `(done, pending)` tuple.

Each waitable type has a natural "wait for" behavior:

* `Sandbox`: waits until the status is `RUNNING`.
* `OperationRef`: waits until the operation completes.
* `Process`: waits until the process completes.

**Parameters**

* `waitables` (`Sequence[Waitable]`): A sequence of `Sandbox`, `OperationRef`, or `Process` objects.
* `num_returns` (`int | None`): If specified, returns after this many waitables complete. If `None`, waits for all to complete.
* `timeout` (`float | None`): The maximum number of seconds to wait. If `None`, waits indefinitely.

**Returns**

* `tuple[list[Waitable], list[Waitable]]`: A tuple of `(done, pending)` lists containing the original waitable objects.

**Raises**

* `ValueError`: If `num_returns` is less than 1.

**Examples**

Wait for all sandboxes to be running:

```python theme={"system"}
sandboxes = [Sandbox.run(...) for _ in range(5)]
done, pending = cwsandbox.wait(sandboxes)
```

Wait for the first two operations to complete:

```python theme={"system"}
refs = [sb.read_file(f) for f in files]
done, pending = cwsandbox.wait(refs, num_returns=2)
```

Wait with a timeout:

```python theme={"system"}
done, pending = cwsandbox.wait(procs, timeout=30.0)
```
