> ## 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.

# Long running tasks

> Keep a Devbox awake while your agent works through a long task.

A Devbox stops once it has been idle for its [idle timeout](https://namespace.so/docs/devbox/lifecycle.md#idle-timeout). Work your agent leaves running on its own, such as an overnight job in a [session](https://namespace.so/docs/devbox/sessions.md), keeps the Devbox awake only briefly, so it can stop partway through. Commands run with [`devbox exec`](https://namespace.so/docs/devbox/exec) don't need this, because they keep the Devbox awake while they run. A task marker tells the Devbox that work is in progress: while one exists, it stays awake. A marker is a file in the directory `$NAMESPACE_DEVBOX_TASKS_DIR` points to. The commands below run from your machine with [`devbox exec`](https://namespace.so/docs/devbox/exec). Inside the Devbox, run the quoted command on its own.

For a process that should run until you stop it, such as a dev server, create a [service](https://namespace.so/docs/devbox/services.md#prevent-idle-shutdown) that keeps the Devbox awake instead.

> [!TIP]
>
> With the [Devbox skill](https://namespace.so/docs/reference/devbox-cli/agent-skills.md), ask your agent in plain language, for example: *"Run the full test suite on my-devbox and keep it awake until it finishes."*

## Keep the Devbox awake during the work

### 1. Mark work in progress

Create a marker before the work starts. Here the marker is named `tests`. Name yours after the task.

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- sh -c 'touch "$NAMESPACE_DEVBOX_TASKS_DIR/tests"'
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.exec(["sh", "-c", 'touch "$NAMESPACE_DEVBOX_TASKS_DIR/tests"']);
```

On Windows:

```bash 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'
```

### 2. Clear the marker when the work ends

Clear it even if the work fails. A marker doesn't expire and survives a restart. While one is left behind, the Devbox doesn't stop for being idle. It keeps running, and is billed for that time, until you clear the marker or stop the Devbox yourself. It still stops at its [maximum duration](https://namespace.so/docs/devbox/lifecycle.md#maximum-duration).

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- sh -c 'rm -f "$NAMESPACE_DEVBOX_TASKS_DIR/tests"'
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
await devbox.exec(["sh", "-c", 'rm -f "$NAMESPACE_DEVBOX_TASKS_DIR/tests"']);
```

On Windows:

```bash 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 -ErrorAction Ignore'
```

## Find leftover markers

List the markers keeping the Devbox awake, then clear any that are left over. An empty result means none.

```bash CLI theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- sh -c 'ls "$NAMESPACE_DEVBOX_TASKS_DIR"'
```

```typescript TS SDK theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const { stdout } = await devbox.exec([
  "sh", "-c", 'ls "$NAMESPACE_DEVBOX_TASKS_DIR"',
]);
```

On Windows:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
devbox exec my-devbox -- powershell.exe -Command \
  'Get-ChildItem $env:NAMESPACE_DEVBOX_TASKS_DIR'
```

## Related

* [Lifecycle](https://namespace.so/docs/devbox/lifecycle.md#idle-timeout) for what keeps a Devbox awake.
* [Services](https://namespace.so/docs/devbox/services.md) for processes that should always run.
* [Devbox skill](https://namespace.so/docs/reference/devbox-cli/agent-skills.md) to let your agent manage markers for you.


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