# How to Configure allowedDirectories and blockedCommands for Security in Desktop Commander

> Secure Desktop Commander by configuring allowedDirectories and blockedCommands. Learn how to whitelist file paths and blacklist shell commands in config.json to prevent unauthorized access.

- Repository: [Eduard Ruzga/DesktopCommanderMCP](https://github.com/wonderwhy-er/DesktopCommanderMCP)
- Tags: how-to-guide
- Published: 2026-07-25

---

**Desktop Commander stores security settings in [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json) where `allowedDirectories` whitelists filesystem paths and `blockedCommands` blacklists shell commands to prevent unauthorized access.**

Desktop Commander is an MCP (Model Context Protocol) server that provides filesystem and terminal access to AI assistants. Configuring `allowedDirectories` and `blockedCommands` in the user configuration file lets you restrict which paths the server can access and which shell commands it can execute, creating a critical security boundary between AI agents and your host system.

## Understanding the Security Configuration Fields

Desktop Commander defines its security controls in [`src/config-field-definitions.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-field-definitions.ts). Two arrays govern access:

- **allowedDirectories**: A whitelist of filesystem paths the server is permitted to read or write. When empty, the application defaults to full filesystem access.
- **blockedCommands**: A blacklist of shell commands that Desktop Commander refuses to execute, even if explicitly requested.

According to the source code in [`src/config-field-definitions.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-field-definitions.ts) (lines 11-20), both fields default to empty arrays. The `ConfigManager` in [`src/config-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-manager.ts) (lines 182-183) loads these values from [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json) and normalizes them, applying the empty array defaults when no user configuration exists.

## How Security Restrictions Are Enforced

The server enforces these policies at the point of execution, validating every filesystem operation and command invocation against your configuration.

### Filesystem Path Validation

Before performing any read or write operation, the **Filesystem tool** calls `getAllowedDirs()` from [`src/tools/filesystem.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/filesystem.ts) (lines 172-203). This method checks whether the target path falls within one of the directories listed in `allowedDirectories`. If the check fails, the operation aborts immediately with an error listing the permitted directories.

### Command Execution Blocking

When a shell command is about to spawn, the **CommandManager** inspects `config.blockedCommands` in [`src/command-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/command-manager.ts) (lines 233-246). If the command name or its base name appears in the blocked list, the request is rejected before execution begins.

## Configuring allowedDirectories to Restrict Filesystem Access

To limit filesystem access to specific directories, edit your [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json) file:

```json
{
  "allowedDirectories": [
    "/home/alice/projects",
    "/etc/my-secure-config"
  ],
  "blockedCommands": []
}

```

With this configuration, any filesystem call targeting paths outside `/home/alice/projects` or `/etc/my-secure-config` will be rejected with an error message specifying the allowed directories. If `allowedDirectories` remains empty, Desktop Commander maintains full filesystem access.

## Configuring blockedCommands to Prevent Dangerous Operations

To prohibit specific shell commands, add them to the `blockedCommands` array:

```json
{
  "allowedDirectories": [],
  "blockedCommands": [
    "rm",
    "shutdown",
    "reboot",
    "mkfs"
  ]
}

```

This prevents execution of any command matching these names. For example, attempting to run `rm -rf /` will trigger the CommandManager to return an error: `Command not allowed: rm`. The check occurs before the command reaches the shell, blocking both the command and any arguments.

## Managing Configuration Programmatically

You can update security settings programmatically using the `ConfigManager` API:

```typescript
import { configManager } from './config-manager';

// Append a new allowed directory
await configManager.setValue('allowedDirectories', [
  ...await configManager.getValue('allowedDirectories'),
  '/var/www'
]);

// Add a blocked command
await configManager.setValue('blockedCommands', [
  ...await configManager.getValue('blockedCommands'),
  'chmod'
]);

```

The `setValue` method writes changes back to [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json) immediately, and subsequent operations enforce the new restrictions without requiring a server restart.

To retrieve current settings for debugging or UI display:

```typescript
import { getConfig } from './config-manager';

const cfg = await getConfig();
console.log('Allowed directories:', cfg.allowedDirectories);
console.log('Blocked commands:', cfg.blockedCommands);

```

## Editing Settings via the Config Editor UI

Desktop Commander includes a web-based **Config Editor** located in [`src/ui/config-editor/src/app.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/ui/config-editor/src/app.ts). This interface renders `allowedDirectories` and `blockedCommands` as editable arrays.

According to the source (lines 310-327), the UI displays "All folders allowed (no restriction)" when `allowedDirectories` is empty, otherwise showing the count of restricted folders. The `blockedCommands` list appears as a simple text field where each line represents a blocked command (lines 319-321).

## Summary

- **Security fields** (`allowedDirectories` and `blockedCommands`) are defined in [`src/config-field-definitions.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-field-definitions.ts) and stored in [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json).
- **Empty arrays** mean no restrictions: full filesystem access and no command blocking.
- **Filesystem validation** occurs in [`src/tools/filesystem.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/filesystem.ts) via `getAllowedDirs()`, rejecting paths outside whitelisted directories.
- **Command blocking** happens in [`src/command-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/command-manager.ts) (lines 233-246), intercepting blocked commands before execution.
- **Programmatic updates** use `configManager.setValue()` to modify arrays dynamically.
- **UI editing** is available through the Config Editor component in [`src/ui/config-editor/src/app.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/ui/config-editor/src/app.ts).

## Frequently Asked Questions

### What happens if allowedDirectories is empty?

When `allowedDirectories` is an empty array (the default), Desktop Commander grants unrestricted filesystem access. The Filesystem tool in [`src/tools/filesystem.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/tools/filesystem.ts) skips path validation entirely, allowing operations on any path the host user can access.

### Can I use wildcards or patterns in blockedCommands?

No. The CommandManager in [`src/command-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/command-manager.ts) performs exact string matching against the command base name. You must specify the full command name (e.g., `rm` not `r*`) to block it. Pattern matching or regex is not implemented in the current version.

### Does Desktop Commander block command arguments or just the command name?

The security check examines only the command name or its base name, not the arguments. As implemented in [`src/command-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/command-manager.ts) (lines 233-246), blocking `rm` prevents any invocation of `rm`, including `rm -rf /`, because the base name matches the blocked list. However, you cannot block specific argument combinations while allowing others.

### Where is the config.json file located?

The `ConfigManager` in [`src/config-manager.ts`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/src/config-manager.ts) loads [`config.json`](https://github.com/wonderwhy-er/DesktopCommanderMCP/blob/main/config.json) from the Desktop Commander installation directory. The exact path depends on your installation method, but the file resides in the server root where the application executes. Changes made via the Config Editor UI or `configManager.setValue()` persist to this location immediately.