What Are `blockedCommands` in Desktop Commander MCP Configuration?
The blockedCommands configuration in Desktop Commander MCP is a safety blocklist that prevents execution of dangerous shell commands like format, rm -rf, sudo, and shutdown before they reach the operating system.
Desktop Commander MCP implements a configurable command blocklist to protect the host system from accidental or malicious destructive operations. The blockedCommands array stores this blocklist in the server configuration and enforces it on every terminal command execution. This article explains how the blocklist works, what commands it includes by default, and how to customize it programmatically or through the UI.
Default Blocked Commands in Desktop Commander MCP
The default blockedCommands list is defined in src/config-manager.ts at lines 25-71. The list covers six high-risk categories:
| Category | Blocked Commands |
|---|---|
| Disk & partition tools | mkfs, format, mount, umount, fdisk, dd, parted, diskpart |
| System administration | sudo, su, passwd, adduser, useradd, usermod, groupadd, chsh, visudo |
| Power control | shutdown, reboot, halt, poweroff, init |
| Network & security | iptables, firewall, netsh |
| Windows system tools | sfc, bcdedit, reg, net, sc, runas, cipher, takeown |
These commands can format drives, modify user accounts, change power states, or alter system-level security settings. The default configuration deliberately errs on the side of caution—blocking any command that could damage the system or compromise security.
How blockedCommands Enforces Command Restrictions
The blocklist enforcement follows a four-step pipeline implemented across two core files:
- Configuration loading –
ConfigManagerinitializes the defaultblockedCommandsarray on first run - Command preprocessing –
CommandManager.execute()callsisAllowedCommand()before execution - Blocklist validation – The base command is checked against the current
blockedCommandsarray - Execution or rejection – Blocked commands return
{ blocked: true }to the client without reaching the OS
The core validation logic in src/command-manager.ts (lines 231-251) works as follows:
const blockedCommands = config.blockedCommands || [];
if (blockedCommands.includes(baseCommand)) return false;
When a command is blocked, the REPL client receives the blocked: true flag and the UI displays a warning instead of executing the command.
Customizing the blockedCommands Configuration
You can modify the blockedCommands array at runtime using the ConfigManager API or through the desktop UI at Settings → Blocked Commands.
Reading the Current Blocklist
import { configManager } from './config-manager.js';
async function showBlocked() {
const cfg = await configManager.getConfig();
console.log('Blocked commands:', cfg.blockedCommands);
}
showBlocked();
Adding a Command to the Blocklist
import { configManager } from './config-manager.js';
async function blockWget() {
const cfg = await configManager.getConfig();
const newList = [...(cfg.blockedCommands ?? []), 'wget'];
await configManager.setValue('blockedCommands', newList);
console.log('Updated blocklist with wget');
}
blockWget();
Testing Blocklist Enforcement
import { CommandManager } from './command-manager.js';
import { configManager } from './config-manager.js';
async function tryRun() {
await configManager.setValue('blockedCommands', ['rm']);
const result = await CommandManager.execute('rm -rf /tmp/test');
console.log(result.blocked ? 'Command blocked' : 'Command executed');
}
tryRun();
Disabling the Blocklist (Not Recommended)
Setting blockedCommands to an empty array removes all restrictions:
await configManager.setValue('blockedCommands', []);
Security warning: An empty blocklist exposes the host to destructive commands. Use this only in isolated, sandboxed environments.
Key Source Files for blockedCommands
| File | Purpose |
|---|---|
src/config-field-definitions.ts |
Defines the blockedCommands schema and type constraints |
src/config-manager.ts |
Creates the default blocklist (lines 25-71) and provides the configuration API |
src/command-manager.ts |
Enforces blockedCommands via isAllowedCommand() (lines 231-251) |
test/test-blocked-commands.js |
Unit tests verifying blocklist behavior across edge cases |
Summary
blockedCommandsis a configurable array in Desktop Commander MCP that prevents execution of dangerous shell commands- Default protection covers 30+ commands across disk tools, system administration, power control, and network security
- Enforcement happens in
CommandManager.isAllowedCommand()before any command reaches the operating system - Customization is available via
configManager.setValue('blockedCommands', ...)or the Settings UI - Security design treats the blocklist as a safety guard—disabling it requires explicit action and carries significant risk
Frequently Asked Questions
What happens when a command is in the blockedCommands list?
The command is rejected before execution. CommandManager.execute() returns { blocked: true } to the client, and the UI displays a warning message. The command never spawns a shell process or interacts with the operating system.
Can I block command arguments or substrings, not just base commands?
No. The current implementation in src/command-manager.ts extracts and checks only the base command name. For example, blocking rm prevents rm -rf / but also blocks benign rm usage. You cannot block specific argument patterns like rm -rf while allowing rm -i.
Where is the blockedCommands configuration persisted?
The configuration is managed by ConfigManager in src/config-manager.ts. It persists to the server's configuration store, shared across sessions. Changes made via the API or UI are immediately active for all subsequent command executions.
Does Desktop Commander MCP ship with blockedCommands enabled by default?
Yes. The server initializes with a conservative default blocklist defined at lines 25-71 of src/config-manager.ts. This ensures protection is active from first installation without requiring manual configuration.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →