# spawn

Spawns a new remote Cartesi machine server process, binding it to a specified address. Returns a [RemoteCartesiMachine](/cm/api/remote-cartesi-machine) instance that can be used to interact with the remote server. This is the main entry point for starting a new remote machine server from your application.

## Function Signature

```ts
spawn(address?: string, timeout?: number): RemoteCartesiMachine
```

* `address` (optional): The address (`host:port`) to bind the new remote machine server, where `host` must be `127.0.0.1`. Port can be `0` to request an ephemeral port. Defaults to `"127.0.0.1:0"`.
* `timeout` (optional): Maximum time in milliseconds to wait for the remote server to spawn before giving up and returning an error. Use `-1` for no timeout.

## Example

```ts twoslash
import { spawn } from "@deroll/cm";

// Spawn a new remote machine server with default address (127.0.0.1:0)
const remoteMachine = await spawn();

// You can now use remoteMachine as a RemoteCartesiMachine
const version = remoteMachine.getServerVersion();
console.log("Remote server version:", version);

// Don't forget to shutdown the server when done
remoteMachine.shutdown();
```

:::info
The `cartesi-jsonrpc-machine` executable must be in the path, or the environment variable `CARTESI_JSONRPC_MACHINE` must point directly to the executable.
:::
