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

# Lifecycle

> Sleep, wake, and delete Dedalus Machines

export const Pop = ({content, children}) => {
  const [open, setOpen] = useState(false);
  const [hoverOpen, setHoverOpen] = useState(false);
  const [isDark, setIsDark] = useState(false);
  const triggerRef = useRef(null);
  const portalRef = useRef(null);
  const closeTimer = useRef(null);
  const isOpen = open || hoverOpen;
  useEffect(() => {
    const probe = () => setIsDark(document.documentElement.classList.contains("dark"));
    probe();
    const obs = new MutationObserver(probe);
    obs.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return () => obs.disconnect();
  }, []);
  const onEnter = () => {
    clearTimeout(closeTimer.current);
    setHoverOpen(true);
  };
  const onLeave = () => {
    closeTimer.current = setTimeout(() => setHoverOpen(false), 150);
  };
  useEffect(() => {
    if (!isOpen) return;
    const node = document.createElement("div");
    node.setAttribute("role", "dialog");
    node.textContent = content;
    document.body.appendChild(node);
    portalRef.current = node;
    const dark = document.documentElement.classList.contains("dark");
    Object.assign(node.style, {
      position: "fixed",
      zIndex: "9999",
      maxWidth: "20rem",
      width: "max-content",
      padding: "0.5rem 0.75rem",
      fontSize: "0.875rem",
      lineHeight: "1.55",
      color: dark ? "rgb(244, 244, 245)" : "rgb(39, 39, 42)",
      backgroundColor: dark ? "rgba(24, 24, 27, 0.4)" : "rgba(255, 255, 255, 0.4)",
      backdropFilter: "blur(4px) saturate(160%)",
      WebkitBackdropFilter: "blur(4px) saturate(160%)",
      border: dark ? "1px solid rgba(255, 255, 255, 0.18)" : "1px solid rgba(0, 0, 0, 0.16)",
      boxShadow: "0 8px 32px rgba(0, 0, 0, 0.12)",
      opacity: "0",
      transform: "translateY(-4px)",
      transition: "opacity 180ms cubic-bezier(0.16, 1, 0.3, 1), transform 180ms cubic-bezier(0.16, 1, 0.3, 1)"
    });
    const place = () => {
      const r = triggerRef.current?.getBoundingClientRect();
      if (!r || !portalRef.current) return;
      portalRef.current.style.left = `${r.left}px`;
      portalRef.current.style.top = `${r.bottom + 8}px`;
    };
    place();
    requestAnimationFrame(() => {
      node.style.opacity = "1";
      node.style.transform = "translateY(0)";
    });
    node.addEventListener("mouseenter", onEnter);
    node.addEventListener("mouseleave", onLeave);
    window.addEventListener("scroll", place, true);
    window.addEventListener("resize", place);
    return () => {
      window.removeEventListener("scroll", place, true);
      window.removeEventListener("resize", place);
      node.remove();
      portalRef.current = null;
    };
  }, [isOpen, content]);
  useEffect(() => {
    if (!open) return;
    const dismiss = e => {
      const inside = triggerRef.current?.contains(e.target) || portalRef.current?.contains(e.target);
      if (!inside) {
        setOpen(false);
        setHoverOpen(false);
      }
    };
    const onKey = e => e.key === "Escape" && (setOpen(false), setHoverOpen(false));
    document.addEventListener("mousedown", dismiss);
    document.addEventListener("keydown", onKey);
    return () => {
      document.removeEventListener("mousedown", dismiss);
      document.removeEventListener("keydown", onKey);
    };
  }, [open]);
  return <button ref={triggerRef} type="button" onClick={() => setOpen(v => !v)} onMouseEnter={onEnter} onMouseLeave={onLeave} aria-expanded={isOpen} className="cursor-pointer bg-transparent border-0 p-0 text-inherit underline decoration-dotted underline-offset-[3px] transition-colors" style={{
    textDecorationColor: isDark ? "rgb(113, 113, 122)" : "rgb(161, 161, 170)"
  }}>
			{children}
		</button>;
};

Machines have four <Pop content="The machine lifecycle phases: running, sleeping, starting, and destroyed.">states</Pop>: **running**, **sleeping**, **starting**, and **destroyed**. You control transitions between them.

## List machines

Returns every machine in your account, including sleeping machines.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines list
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  machines = client.machines.list()
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const machines = await client.machines.list();
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  machines, _ := client.Machines.List(ctx, dedalus.MachineListParams{})
  fmt.Println(len(machines.Items))
  ```
</CodeGroup>

## Get machine details

Returns a point-in-time snapshot of the machine object: ID, phase, CPU,
memory, storage, autosleep policy, IP address, and timestamps.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines retrieve --machine-id <machine_id>
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dm = client.machines.retrieve(machine_id="<machine_id>")
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const dm = await client.machines.retrieve({ machine_id: "<machine_id>" });
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dm, _ := client.Machines.Get(ctx, dedalus.MachineGetParams{
      MachineID: machineID,
  })
  fmt.Println(dm.Status.Phase)
  ```
</CodeGroup>

<Accordion title="Parameters">
  <ParamField path="machine_id" type="string" required>
    The machine to retrieve.
  </ParamField>
</Accordion>

## Watch

Streams state changes. Use it to monitor sleep, wake, and delete. The stream closes when the machine reaches a stable phase.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines watch --machine-id <machine_id>
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import json

  with client.machines.with_streaming_response.watch(machine_id="<machine_id>") as resp:
      for line in resp.iter_lines():
          if line.startswith("data:"):
              payload = json.loads(line[5:])
              print(payload["status"]["phase"])
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const stream = await client.machines.watch({ machine_id: "<machine_id>" });
  for await (const evt of stream) {
    console.log(evt.status.phase);
  }
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  stream := client.Machines.WatchStreaming(ctx, dedalus.MachineWatchParams{
      MachineID: machineID,
  })
  for stream.Next() {
      fmt.Println(stream.Current().Status.Phase)
  }
  ```
</CodeGroup>

<Accordion title="Parameters">
  <ParamField path="machine_id" type="string" required>
    The machine to watch.
  </ParamField>
</Accordion>

## Auto-sleep

By default, machines auto-sleep after 5 idle minutes. Set `autosleep` on create or update. Use `never` to disable it.

Activity includes executions, terminal traffic, SSH traffic, port traffic, and CPU work from user-owned processes inside the VM.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines update --machine-id <machine_id> --autosleep 15m
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.machines.update(
      machine_id="<machine_id>",
      autosleep="15m",
  )
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  await client.machines.update({
    machine_id: "<machine_id>",
    autosleep: "15m",
  });
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dm, _ := client.Machines.Update(ctx, dedalus.MachineUpdateParams{
      MachineID: machineID,
      UpdateParams: dedalus.UpdateParams{
          Autosleep: dedalus.String("15m"),
      },
  })
  fmt.Println(dm.AutosleepSeconds)
  ```
</CodeGroup>

<Accordion title="Parameters">
  <ParamField body="autosleep" type="string">
    Idle window before auto-sleep. Accepts units like `30s`, `15m`, `2h`, `1w3d`, raw seconds like `"1800"`, or `never`.
  </ParamField>
</Accordion>

## Sleep

Sleeping machines have zero compute cost. Storage persists.

Sleep preserves the machine's root filesystem. Paths such as `/etc`, `/home`,
`/root`, `/usr/local`, and `/var` persist unless you mount something else over
them.

Kernel and runtime filesystems are recreated on each wake. Paths such as
`/proc`, `/sys`, `/dev`, `/run`, and `/dev/shm` are not persistent storage.
Treat `/tmp` as temporary scratch space; use `/var/tmp`, `/home`, `/root`, or
another root-filesystem path for files you need after sleep.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines sleep --machine-id <machine_id>
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.machines.sleep(machine_id="<machine_id>")
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  await client.machines.sleep({ machine_id: "<machine_id>" });
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.Machines.Sleep(ctx, dedalus.MachineSleepParams{
      MachineID: machineID,
  })
  ```
</CodeGroup>

## Wake

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines wake --machine-id <machine_id>
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.machines.wake(machine_id="<machine_id>")
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  await client.machines.wake({ machine_id: "<machine_id>" });
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.Machines.Wake(ctx, dedalus.MachineWakeParams{
      MachineID: machineID,
  })
  ```
</CodeGroup>

<Accordion title="Parameters">
  <ParamField path="machine_id" type="string" required>
    The machine to sleep or wake.
  </ParamField>
</Accordion>

## Delete

Delete the machine.

<CodeGroup>
  ```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark"}}
  dedalus machines delete --machine-id <machine_id>
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.machines.delete(machine_id="<machine_id>")
  ```

  ```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  await client.machines.delete({ machine_id: "<machine_id>" });
  ```

  ```go Go theme={"theme":{"light":"github-light","dark":"github-dark"}}
  client.Machines.Delete(ctx, dedalus.MachineDeleteParams{
      MachineID: machineID,
  })
  ```
</CodeGroup>

<Accordion title="Parameters">
  <ParamField path="machine_id" type="string" required>
    The machine to delete.
  </ParamField>
</Accordion>

<Warning>
  Delete removes the machine from normal use immediately. Storage may be retained for up to 30 days. Contact support for recovery.
</Warning>
