Skip to main content

Enter kernel namespaces from Python

Project description

Travis CI build status

This Python package allows entering Linux kernel namespaces (mount, IPC, net, PID, user and UTS) by doing the “setns” syscall. The command line interface tries to be similar to the nsenter C program.

Requires Python 2.6 or higher

See the introductory blog post “Entering Kernel Namespaces from Python”.

Install from PyPI:

sudo pip3 install nsenter

Install from git source:

python3 install

Example command line usage:

docker run -d --name=redis -t redis
sudo nsenter --all --target=`docker inspect --format '{{ .State.Pid }}' redis` /bin/bash

Example usage from Python:

import subprocess
from nsenter import Namespace

with Namespace(mypid, 'net'):
    # output network interfaces as seen from within the mypid's net NS:
    subprocess.check_output(['ip', 'a'])

# or enter an arbitrary namespace:
with Namespace('/var/run/netns/foo', 'net'):
    # output network interfaces as seen from within the net NS "foo":
    subprocess.check_output(['ip', 'a'])

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nsenter-0.2.tar.gz (4.3 kB view hashes)

Uploaded source

Built Distribution

nsenter-0.2-py3-none-any.whl (12.3 kB view hashes)

Uploaded 3 4

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page