Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandboxing CLI #61

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
52 changes: 52 additions & 0 deletions VM_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Python Sandbox in Linux

Python Sandbox allows you to run your python codes in a complete linux virtual machine. It is easy to use and efficient. The VM is customizable and you can choose your own CPU, disk size, and RAM size.

Two key features:
- Automatic python virtual environment setup.
- Same python instructions

## Numpy Example listed in samples/1st.gif
![](samples/1st.gif)

## Gorilla CLI Example listed in samples/gorillaVM.gif
![](samples/gorillaVM.gif)

## Requirements
Please install `qemu` on your machine. Currently, python-sandbox only works on MacOS with M-sereis chips. Windows and Linux versions are not yet tested, and they may potentially work.

## Usage

Darg all relevant python files into this folder. Then, type to see instructions you need to do:
```bash
$ python python-sandbox.py --help
```

## How It Works

python-sandbox internally use lima to create a linux virtual machine. You can edit your linux machine profile in `python-sandbox.yml`. It regulates all of sandboxes you created and make sure there is no conflicts between sandboxes.

### Arguments
To start a sandbox
```bash
python python-sandbox.py start NEWBOX
```
To stop a sandbox
```bash
python python-sandbox.py stop NEWBOX
```
#### Warning: always remember to stop a sandbox! The sanbox does not close on itself.

To run python
```bash
python python-sandbox.py python PYFILE.py ARGS
```
To pip install relevant packages
```bash
python python-sandbox.py pip install ARGS
```
To show every sandbox status
```bash
python python-sandbox.py show-all
```

5 changes: 3 additions & 2 deletions go_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def prefill_shell_cmd(cmd):
# Use the new attributes
termios.tcsetattr(stdin, termios.TCSANOW, newattr)
# Write the selected command in stdin queue
for c in cmd:
fcntl.ioctl(stdin, termios.TIOCSTI, c)
os.write(stdin, cmd.encode())
# for c in cmd:
# fcntl.ioctl(stdin, termios.TIOCSTI, c)
# Restore TTY attributes for stdin
termios.tcsetattr(stdin, termios.TCSADRAIN, oldattr)

Expand Down
Binary file added lima/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions lima/.brew/lima.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Lima < Formula
desc "Linux virtual machines"
homepage "https://lima-vm.io/"
url "https://github.com/lima-vm/lima/archive/refs/tags/v0.22.0.tar.gz"
sha256 "9ea5b439cf71bb8fc4d831c3a71540baaa4c4420152addf1e32de57a4dc8af96"
license "Apache-2.0"
head "https://github.com/lima-vm/lima.git", branch: "master"

depends_on "go" => :build
depends_on "qemu"

def install
if build.head?
system "make"
else
# VERSION has to be explicitly specified when building from tar.gz, as it does not contain git tags
system "make", "VERSION=#{version}"
end

bin.install Dir["_output/bin/*"]
share.install Dir["_output/share/*"]

# Install shell completions
generate_completions_from_executable(bin/"limactl", "completion", base_name: "limactl")
end

test do
info = JSON.parse shell_output("#{bin}/limactl info")
# Verify that the VM drivers are compiled in
assert_includes info["vmTypes"], "qemu"
assert_includes info["vmTypes"], "vz" if OS.mac? && MacOS.version >= :ventura
# Verify that the template files are installed
template_names = info["templates"].map { |x| x["name"] }
assert_includes template_names, "default"
end
end
290 changes: 290 additions & 0 deletions lima/INSTALL_RECEIPT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
{
"homebrew_version": "4.2.21-8-g55167f2",
"used_options": [

],
"unused_options": [

],
"built_as_bottle": true,
"poured_from_bottle": true,
"loaded_from_api": true,
"installed_as_dependency": false,
"installed_on_request": true,
"changed_files": [

],
"time": 1716675096,
"source_modified_time": 1715052850,
"compiler": "clang",
"aliases": [

],
"runtime_dependencies": [
{
"full_name": "capstone",
"version": "5.0.1",
"revision": 0,
"pkg_version": "5.0.1",
"declared_directly": false
},
{
"full_name": "dtc",
"version": "1.7.0",
"revision": 0,
"pkg_version": "1.7.0",
"declared_directly": false
},
{
"full_name": "pcre2",
"version": "10.43",
"revision": 0,
"pkg_version": "10.43",
"declared_directly": false
},
{
"full_name": "mpdecimal",
"version": "4.0.0",
"revision": 0,
"pkg_version": "4.0.0",
"declared_directly": false
},
{
"full_name": "ca-certificates",
"version": "2024-03-11",
"revision": 0,
"pkg_version": "2024-03-11",
"declared_directly": false
},
{
"full_name": "openssl@3",
"version": "3.3.0",
"revision": 0,
"pkg_version": "3.3.0",
"declared_directly": false
},
{
"full_name": "readline",
"version": "8.2.10",
"revision": 0,
"pkg_version": "8.2.10",
"declared_directly": false
},
{
"full_name": "sqlite",
"version": "3.45.3",
"revision": 0,
"pkg_version": "3.45.3",
"declared_directly": false
},
{
"full_name": "xz",
"version": "5.4.6",
"revision": 0,
"pkg_version": "5.4.6",
"declared_directly": false
},
{
"full_name": "python@3.12",
"version": "3.12.3",
"revision": 0,
"pkg_version": "3.12.3",
"declared_directly": false
},
{
"full_name": "gettext",
"version": "0.22.5",
"revision": 0,
"pkg_version": "0.22.5",
"declared_directly": false
},
{
"full_name": "glib",
"version": "2.80.2",
"revision": 0,
"pkg_version": "2.80.2",
"declared_directly": false
},
{
"full_name": "gmp",
"version": "6.3.0",
"revision": 0,
"pkg_version": "6.3.0",
"declared_directly": false
},
{
"full_name": "libunistring",
"version": "1.2",
"revision": 0,
"pkg_version": "1.2",
"declared_directly": false
},
{
"full_name": "libidn2",
"version": "2.3.7",
"revision": 0,
"pkg_version": "2.3.7",
"declared_directly": false
},
{
"full_name": "libtasn1",
"version": "4.19.0",
"revision": 0,
"pkg_version": "4.19.0",
"declared_directly": false
},
{
"full_name": "nettle",
"version": "3.9.1",
"revision": 0,
"pkg_version": "3.9.1",
"declared_directly": false
},
{
"full_name": "p11-kit",
"version": "0.25.3",
"revision": 0,
"pkg_version": "0.25.3",
"declared_directly": false
},
{
"full_name": "libevent",
"version": "2.1.12",
"revision": 1,
"pkg_version": "2.1.12_1",
"declared_directly": false
},
{
"full_name": "libnghttp2",
"version": "1.61.0",
"revision": 0,
"pkg_version": "1.61.0",
"declared_directly": false
},
{
"full_name": "unbound",
"version": "1.20.0",
"revision": 0,
"pkg_version": "1.20.0",
"declared_directly": false
},
{
"full_name": "gnutls",
"version": "3.8.4",
"revision": 0,
"pkg_version": "3.8.4",
"declared_directly": false
},
{
"full_name": "jpeg-turbo",
"version": "3.0.3",
"revision": 0,
"pkg_version": "3.0.3",
"declared_directly": false
},
{
"full_name": "libpng",
"version": "1.6.43",
"revision": 0,
"pkg_version": "1.6.43",
"declared_directly": false
},
{
"full_name": "libslirp",
"version": "4.8.0",
"revision": 0,
"pkg_version": "4.8.0",
"declared_directly": false
},
{
"full_name": "libssh",
"version": "0.10.6",
"revision": 0,
"pkg_version": "0.10.6",
"declared_directly": false
},
{
"full_name": "libusb",
"version": "1.0.27",
"revision": 0,
"pkg_version": "1.0.27",
"declared_directly": false
},
{
"full_name": "lzo",
"version": "2.10",
"revision": 0,
"pkg_version": "2.10",
"declared_directly": false
},
{
"full_name": "ncurses",
"version": "6.5",
"revision": 0,
"pkg_version": "6.5",
"declared_directly": false
},
{
"full_name": "pixman",
"version": "0.42.2",
"revision": 0,
"pkg_version": "0.42.2",
"declared_directly": false
},
{
"full_name": "snappy",
"version": "1.2.1",
"revision": 0,
"pkg_version": "1.2.1",
"declared_directly": false
},
{
"full_name": "vde",
"version": "2.3.3",
"revision": 0,
"pkg_version": "2.3.3",
"declared_directly": false
},
{
"full_name": "lz4",
"version": "1.9.4",
"revision": 0,
"pkg_version": "1.9.4",
"declared_directly": false
},
{
"full_name": "zstd",
"version": "1.5.6",
"revision": 0,
"pkg_version": "1.5.6",
"declared_directly": false
},
{
"full_name": "qemu",
"version": "9.0.0",
"revision": 0,
"pkg_version": "9.0.0",
"declared_directly": true
}
],
"source": {
"spec": "stable",
"versions": {
"stable": "0.22.0",
"head": null,
"version_scheme": 0
},
"path": "/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/l/lima.rb",
"tap_git_head": null,
"tap": "homebrew/core"
},
"arch": "arm64",
"built_on": {
"os": "Macintosh",
"os_version": "macOS 14.4",
"cpu_family": "dunno",
"xcode": "15.3",
"clt": "15.3.0.0.1.1708646388",
"preferred_perl": "5.34"
}
}
Loading