Os tool security

From RedHatProductSecurity/prodsec-skills · View interactive version

Os tool security is an AI agent skill from the GitHub repository RedHatProductSecurity/prodsec-skills. Enforce least privilege and sandboxing for MCP server OS tool execution. Use when building, configuring, or reviewing MCP servers that execute operating system commands or local tools.

How to use this skill

Skill file

OS Tool Security for MCP Servers

Security Requirement

When MCP servers execute tools in the operating system, they run with the permissions of the MCP server process. The following security controls are required:

  1. Least Privilege: Give the MCP server the lowest permissions necessary to perform its mission.
  2. Privilege Dropping: Drop specific privileges before executing specific commands.
  3. Sandboxing: Use sandboxing mechanisms to prevent executed commands from causing damage.

Command Execution Hygiene

Never pass unsanitized input to a shell. Use safe, parameterized APIs:

import subprocess

# CORRECT - parameterized, no shell
subprocess.run(['echo', user_input], shell=False)

# FORBIDDEN - shell injection risk
import os
os.system(f"echo {user_input}")          # NEVER do this
subprocess.run(f"echo {user_input}", shell=True)  # NEVER do this

Never execute commands with higher privileges than necessary. Never run as root.

Least Privilege

Privilege Dropping

Before executing a command, drop privileges not required for that specific command:

# Drop to restricted user before executing tool command
import os

def execute_tool_command(command, restricted_uid, restricted_gid):
    pid = os.fork()
    if pid == 0:
        os.setgid(restricted_gid)
        os.setuid(restricted_uid)
        os.execvp(command[0], command)
    else:
        _, status = os.waitpid(pid, 0)
        return status

Sandboxing Mechanisms

Use one or more of the following to contain tool execution:

| Mechanism | Description |

|---|---|

| Containers (Podman, Docker) | Isolate tool execution in a container with limited capabilities |

| seccomp | Restrict system calls available to the tool process |

| AppArmor / SELinux | Mandatory access control policies limiting file and network access |

| namespaces | Isolate PID, network, mount, and user namespaces |

| chroot / pivot_root | Restrict filesystem visibility |

| cgroups | Limit CPU, memory, and I/O resources |

Implementation Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.