{"id":38514727,"url":"https://github.com/deepsense-ai/ds-pycontain","last_synced_at":"2026-01-17T06:27:11.544Z","repository":{"id":205139491,"uuid":"713510063","full_name":"deepsense-ai/ds-pycontain","owner":"deepsense-ai","description":"Library to run python REPL in isolated docker container and helpful abstraction for docker containers/images. in python","archived":false,"fork":false,"pushed_at":"2023-11-06T19:14:47.000Z","size":2939,"stargazers_count":9,"open_issues_count":2,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-23T18:07:46.531Z","etag":null,"topics":["agents","containerization","containers","docker","isolation","llms","python","repl"],"latest_commit_sha":null,"homepage":"https://deepsense-ai.github.io/ds-pycontain/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepsense-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-11-02T17:01:05.000Z","updated_at":"2025-04-01T07:08:35.000Z","dependencies_parsed_at":"2023-11-06T13:40:15.644Z","dependency_job_id":null,"html_url":"https://github.com/deepsense-ai/ds-pycontain","commit_stats":null,"previous_names":["deepsense-ai/ds-pycontain"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/deepsense-ai/ds-pycontain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepsense-ai%2Fds-pycontain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepsense-ai%2Fds-pycontain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepsense-ai%2Fds-pycontain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepsense-ai%2Fds-pycontain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepsense-ai","download_url":"https://codeload.github.com/deepsense-ai/ds-pycontain/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepsense-ai%2Fds-pycontain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28502265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T04:31:57.058Z","status":"ssl_error","status_checked_at":"2026-01-17T04:31:45.816Z","response_time":85,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agents","containerization","containers","docker","isolation","llms","python","repl"],"created_at":"2026-01-17T06:27:10.902Z","updated_at":"2026-01-17T06:27:11.537Z","avatar_url":"https://github.com/deepsense-ai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [deepsense.ai](https://deepsense.ai) ds_pycontain\n![CI](https://github.com/deepsense-ai/ds-pycontain/actions/workflows/ci.yml/badge.svg)\n[![PyPI](https://img.shields.io/pypi/v/ds_pycontain?label=pypi%20package)](https://pypi.org/project/ds-pycontain/)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/ds-pycontain)\n\n[Documentation](https://deepsense-ai.github.io/ds-pycontain/)\n\n```bash\npip install ds-pycontain\n```\n\nIt is a simple wrapper library around docker python API to make it easier to use and to provide Python REPL running in a container.\nIn particular it was created for langchain isolated python REPL, so agents can run code in isolation.\n\n**Warning**: This package requires docker to be installed and running on the host machine. It also needs more work to make it secure.\n\nThis package makes it a bit easier to:\n\n* Build docker images from Dockerfiles or in-memory string.\n* Pull docker images from dockerhub (or similar).\n* Run docker container to execute a one-off command.\n* Run docker container to execute a long-running process and communicate with it.\n* Run python commands in a container and get the result.\n\nProject boostraped with ds-template: [https://deepsense-ai.github.io/ds-template/](https://deepsense-ai.github.io/ds-template/).\n\n# Example code snippet\n\n## Execute commands in container running in the background:\n```python\n  from ds_pycontain import DockerContainer, DockerImage, get_docker_client\n\n  client = get_docker_client()\n\n  # This will fetch the image from dockerhub if it is not already present\n  # with the \"latest\" tag. Then container is started and commands are run\n  with DockerContainer(DockerImage.from_tag(\"alpine\")) as container:\n      ret_code, output = container.run(\"touch /animal.txt\")\n      assert ret_code == 0\n\n      ret_code, output = container.run(\"ls /\")\n      assert ret_code == 0\n      assert cast(bytes, output).find(b\"animal.txt\") \u003e= 0\n```\n\n## Docker images\n```python\nfrom ds_pycontain import DockerImage\n\n# pull or use alpine:latest\nimage = DockerImage.from_tag(\"alpine\")\n# use provided tag to pull/use the image\nimage = DockerImage.from_tag(\"python\", tag=\"3.9-slim\")\n#  use this dockerfile to build a new local image\nimage = DockerImage.from_dockerfile(\"example/Dockerfile\")\n# you can provide a directory path which contains Dockerfile, set custom image name\nimage = DockerImage.from_dockerfile(\"path/to/dir_with_Dockerfile/\", name=\"cow\")\n```\n\n## Python REPL running in docker container\n```python\n  from ds_pycontain.python_dockerized_repl import PythonContainerREPL\n\n  # To start python REPL in container it is easy,\n  # just be aware that it will take some time to start the container\n  # and ports might be allocated by OS, so use different port/retry\n  # if you get error.\n  repl = PythonContainerREPL(port=7121)\n\n  # You can run python commands in the container\n  # and it will keep state between commands.\n  out1 = repl.exec(\"x = [1, 2, 3]\")\n  assert out1 == \"\"\n  # Eval returns string representation of the python command\n  # as it would be in python REPL:\n  out2 = repl.eval(\"len(x)\")\n  assert out2 == \"3\"\n\n  # Exec returns captured standard output (stdout)\n  # so it won't return anything in this case:\n  out3 = repl.exec(\"len(x)\")\n  assert out3 == \"\"\n  # but exec with print works:\n  out4 = repl.exec(\"print(len(x))\")\n  assert out4 == \"3\\n\"\n\n  # You can also get error messages if code is wrong:\n  err = repl.exec(\"print(x\")\n  assert \"SyntaxError\" in err\n```\n\n# Setup developer environment\n\nTo start, you need to setup your local machine.\n\n## Setup venv\n\nYou need to setup virtual environment, simplest way is to run from project root directory:\n\n```bash\n$ ./setup_dev_env.sh\n$ source venv/bin/activate\n```\nThis will create a new venv and run `pip install -r requirements-dev.txt`.\n\n## Install pre-commit\n\nTo ensure code quality we use pre-commit hook with several checks. Setup it by:\n\n```\npre-commit install\n```\n\nAll updated files will be reformatted and linted before the commit.\n\nTo reformat and lint all files in the project, use:\n\n`pre-commit run --all-files`\n\nThe used linters are configured in `.pre-commit-config.yaml`. You can use `pre-commit autoupdate` to bump tools to the latest versions.\n\n# Project documentation\n\nIn `docs/` directory are Sphinx RST/Markdown files.\n\nTo build documentation locally, in your configured environment, you can use `build_docs.sh` script:\n\n```bash\n$ ./build_docs.sh\n```\n\nThen open `public/index.html` file.\n\nPlease read the official [Sphinx documentation](https://www.sphinx-doc.org/en/master/) for more details.\n\n\n\n# Semantic version bump\n\nTo bump version of the library please use `bump2version` which will update all version strings.\n\nNOTE: Configuration is in `.bumpversion.cfg` and **this is a main file defining version which should be updated only with bump2version**.\n\nFor convenience there is bash script which will create commit, to use it call:\n\n```bash\n# to create a new commit by increasing one semvar:\n$ ./bump_version.sh minor\n$ ./bump_version.sh major\n$ ./bump_version.sh patch\n# to see what is going to change run:\n$ ./bump_version.sh --dry-run major\n```\nScript updates **VERSION** file and setup.cfg automatically uses that version.\n\nYou can configure it to update version string in other files as well - please check out the bump2version configuration file.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsense-ai%2Fds-pycontain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepsense-ai%2Fds-pycontain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsense-ai%2Fds-pycontain/lists"}