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

# Running long tasks

> Keep a Devbox running while a build, test suite, or agent works, and clean up afterwards.

A Devbox stops automatically once it has been inactive for the length of its [idle timeout](https://namespace.so/docs/devbox/lifecycle.md#idle-timeout). Because activity is measured by connections and sessions rather than by load, a long build or an agent working through a large task can be interrupted before it finishes, whether you started it with `devbox exec` or from inside a session.

The solution is to tell the Devbox that work is in progress, by creating a task marker. For a process that runs until you stop it, such as a dev server, run it as a [service](https://namespace.so/docs/devbox/services.md#prevent-idle-shutdown) with idle shutdown prevention instead.

> [!NOTE]
>
> Task markers are files stored in the directory given by the `NAMESPACE_DEVBOX_TASKS_DIR` environment variable. While at least one marker exists, the Devbox is treated as active and the idle countdown does not start.

## Keep a Devbox running

The steps below run inside the Devbox, in a shell opened with `devbox ssh` or in a [session](https://namespace.so/docs/devbox/connecting.md#sessions).

### 1. Create a marker

Create a file in the task marker directory before the work begins:

```bash Linux & macOS theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
touch "$NAMESPACE_DEVBOX_TASKS_DIR/tests"
```

```powershell wrap Windows theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
New-Item -ItemType File "$env:NAMESPACE_DEVBOX_TASKS_DIR/tests" -Force
```

> [!TIP]
>
> The name is yours to choose. Use something that identifies the work, because a marker left behind is easier to trace to its owner than a file called `task`.

### 2. Run the work

For example, start the build, test suite, or agent task as you normally would.

The Devbox stays running for as long as the marker is in place, whether or not anything is connected to it.

### 3. Remove the marker

Remove your marker once the work finishes, including if it fails:

```bash Linux & macOS theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
rm -f "$NAMESPACE_DEVBOX_TASKS_DIR/tests"
```

```powershell wrap Windows theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Remove-Item "$env:NAMESPACE_DEVBOX_TASKS_DIR/tests" -Force
```

This restarts the idle countdown, so the Devbox stops once the timeout elapses with no other activity.

A marker prevents idle shutdown, but does not extend the Devbox's [maximum duration](https://namespace.so/docs/devbox/lifecycle.md#maximum-duration).

## Have an agent mark its own work

An agent working unattended is the case this matters most for: it holds no SSH connection of its own, and a long task can outlast the idle timeout. Ask the agent to create a marker while it works:

```text wrap Agent Prompt theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Before starting long-running work, create a marker file under $NAMESPACE_DEVBOX_TASKS_DIR named after the task, and delete it when the work is done, including if it fails.
```

Putting the same instruction in the repository's agent instructions file, such as `AGENTS.md` or `CLAUDE.md`, applies it to every session without repeating the prompt.

## Clean up leftover markers

A marker does not expire, and on a persistent Devbox it survives a restart. If one is never removed, because the work failed before its cleanup ran or the process was killed, the Devbox is treated as active indefinitely and never stops on idle. Stopping it with `devbox stop` still works, but the idle timeout no longer does anything for it.

List markers and remove only the one left by your finished task:

> [tab] List markers
>
> See which markers are currently in place:
>
> ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> ls "$NAMESPACE_DEVBOX_TASKS_DIR"
> ```
>
> In PowerShell, use `Get-ChildItem $env:NAMESPACE_DEVBOX_TASKS_DIR`.
>
> An empty directory means no marker is keeping the Devbox running.

> [tab] Remove marker
>
> Remove the marker for your finished task:
>
> ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> rm -f "$NAMESPACE_DEVBOX_TASKS_DIR/tests"
> ```
>
> In PowerShell, use `Remove-Item "$env:NAMESPACE_DEVBOX_TASKS_DIR/tests" -Force`.

Removing the last marker restarts the idle countdown, so the Devbox stops once the timeout elapses with no other activity.

## Mark work from your own machine

You do not have to be inside the Devbox to manage a marker. [`devbox exec`](https://namespace.so/docs/devbox/exec) runs a single command in the Devbox and returns. Invoke the shell for the Devbox's operating system explicitly:

> [tab] Add marker
>
> Create the marker before the work begins:
>
> ```bash wrap Linux & macOS theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> devbox exec my-devbox -- sh -c 'touch "$NAMESPACE_DEVBOX_TASKS_DIR/tests"'
> ```
>
> ```bash wrap Windows theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> devbox exec my-devbox -- powershell.exe -Command 'New-Item -ItemType File "$env:NAMESPACE_DEVBOX_TASKS_DIR/tests" -Force'
> ```

> [tab] Remove marker
>
> Remove it once the work finishes:
>
> ```bash wrap Linux & macOS theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> devbox exec my-devbox -- sh -c 'rm -f "$NAMESPACE_DEVBOX_TASKS_DIR/tests"'
> ```
>
> ```bash wrap Windows theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
> devbox exec my-devbox -- powershell.exe -Command 'Remove-Item "$env:NAMESPACE_DEVBOX_TASKS_DIR/tests" -Force'
> ```

Use this when the work spans several commands, or several executions, and you are driving them from outside. It is also what protects a [detached execution](https://namespace.so/docs/devbox/exec.md#detached-executions), which keeps running after your CLI exits but ends if the Devbox stops.

Because each command is a separate execution, nothing removes the marker for you. Anything that stops you before the last command leaves it in place.

## Related topics

> [card] [Devbox Lifecycle](https://namespace.so/docs/devbox/lifecycle.md#idle-timeout)
>
> Configure the idle timeout and see which signals count as activity.

> [card] [Agent Skills](https://namespace.so/docs/reference/devbox-cli/agent-skills.md)
>
> Let a coding agent create and drive Devboxes for you.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.