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

# Merge into

> Commit a fork child as the new state of its parent.

<ParamField path="parent" type="string" required>
  The parent sandbox id.
</ParamField>

<ParamField path="winner" type="string" required>
  A child sandbox id (typically a fork of `parent`) whose state should
  replace `parent`'s.
</ParamField>

<RequestExample>
  ```bash curl theme={null}
  curl -X POST https://api.podflare.ai/v1/sandboxes/$PARENT/merge_into/$WINNER
  ```

  ```python Python theme={null}
  parent.merge_into(winner)
  # parent.id still works, now drives winner's VM.
  # winner.close() is a no-op afterward (marked defunct).
  ```

  ```ts TypeScript theme={null}
  await parent.mergeInto(winner);
  // parent.id still works; winner is defunct.
  ```
</RequestExample>

<ResponseExample>
  ```http 204 No Content theme={null}
  ```
</ResponseExample>

## What actually happens

Atomically swap: parent's microVM is destroyed and the winner's microVM
takes over parent's id. After the call:

* `parent.id` is still a valid sandbox id, but it now drives the
  winner's underlying VM.
* `winner.id` is no longer a live sandbox. The SDK flags the `winner`
  object so its `close()` becomes a no-op (prevents double-destroy).
* **Siblings are NOT touched.** If you forked `n=5` and one is the
  winner, the other 4 are still alive — the caller destroys them
  explicitly.

## Idempotency

* Merging the same winner twice: second call returns 404 (winner id
  gone after first merge).
* Merging a sandbox into itself: 400.

## Typical pattern

```python theme={null}
children = parent.fork(n=5)
try:
    results = [c.run_code(plan) for c, plan in zip(children, plans)]
    winner = children[pick_best_index(results)]
    parent.merge_into(winner)
finally:
    for c in children:
        if c is not winner:
            c.close()
```
