You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLAUDE.md
+58-20Lines changed: 58 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,23 @@ Project goals:
12
12
-**Performance**: Fast execution through compile-time optimizations and efficient memory layout
13
13
-**Simplicity**: Clean, understandable implementation focused on a Python subset
14
14
-**Snapshotting and iteration**: Plan is to allow code to be iteratively executed and snapshotted at each function call
15
+
-**Cross-platform**: Runs on Linux, macOS, and Windows (and any other OS that can run Rust)
15
16
- Targets the latest stable version of Python, currently Python 3.14
16
17
18
+
## Cross-Platform Requirements
19
+
20
+
Monty must work identically on Linux, macOS, and Windows. Within the Monty sandbox,
21
+
paths always use POSIX/Linux-style forward slashes (`/`) regardless of the host OS.
22
+
The `MountTable` handles translating between virtual POSIX paths and host-native paths.
23
+
24
+
Key rules:
25
+
-**Virtual paths** are always POSIX-style (`/mnt/data/file.txt`), never Windows-style
26
+
-**Host paths** use `std::path::Path`/`PathBuf` which handles OS differences automatically
27
+
- Avoid `#[cfg(unix)]`-only code in the main crate — all features must work on all platforms
28
+
- Tests in `crates/monty/tests/` should be cross-platform; use helper functions for
29
+
OS-specific APIs like symlink creation (see `symlink_file`/`symlink_dir` in `fs_security.rs`)
30
+
- CI runs `cargo test -p monty --features ref-count-panic` on Linux, macOS, and Windows
31
+
17
32
## Important Security Notice
18
33
19
34
It's ABSOLUTELY CRITICAL that there's no way for code run in a Monty sandbox to access the host filesystem, or environment or to in any way "escape the sandbox".
@@ -37,6 +52,27 @@ Possible security risks to consider:
37
52
* information leakage via timing or error messages
38
53
* Python/Javascript/Rust APIs that accidentally allow developers to expose their host to monty code
39
54
55
+
## Filesystem Mounts (`crates/monty/src/fs/`)
56
+
57
+
The `MountTable` allows mounting real host directories into the sandbox at virtual paths,
58
+
with configurable access modes (ReadWrite, ReadOnly, OverlayMemory).
59
+
60
+
**CRITICAL SECURITY INVARIANT:** The monty runtime MUST NEVER read, write, or
61
+
obtain any information about any file or directory outside the specific directory
62
+
that is mounted. This is enforced by:
63
+
64
+
- Path canonicalization after mapping virtual → host paths
65
+
- Boundary checks verifying canonical paths remain within the mount
66
+
- Symlink resolution that rejects links pointing outside the mount
67
+
- Virtual-space normalization that prevents `..` escape
68
+
-`Resolve` and `Absolute` returning virtual paths, never host paths
69
+
- Null byte rejection in all paths
70
+
71
+
All path resolution goes through `fs::path_security::resolve_path()` which is
72
+
the sole security boundary. **Changes to `path_security.rs` require careful security review.**
73
+
74
+
`heap.rs` and `path_security.rs` are the two most security-critical files in the codebase.
75
+
40
76
## Bytecode VM Architecture
41
77
42
78
Monty is implemented as a bytecode VM, same as CPython.
@@ -492,26 +528,6 @@ Container types (`List`, `Tuple`, `Dict`) also have `clone_with_heap()` methods.
492
528
493
529
**Resource limits**: When resource limits (allocations, memory, time) are exceeded, execution terminates with a `ResourceError`. No guarantees are made about the state of the heap or reference counts after a resource limit is exceeded. The heap may contain orphaned objects with incorrect refcounts. This is acceptable because resource exhaustion is a terminal error - the execution context should be discarded.
494
530
495
-
## NOTES
496
-
497
-
ALWAYS consider code quality when adding new code, if functions are getting too complex or code is duplicated, move relevant logic to a new file.
498
-
Make sure functions are added in the most logical place, e.g. as methods on a struct where appropriate.
499
-
500
-
The code should follow the "newspaper" style where public and primary functions are at the top of the file, followed by private functions and utilities.
501
-
ALWAYS put utility, private functions and "sub functions" underneath the function they're used in.
502
-
503
-
It is important to the long term health of the project and maintainability of the codebase that code is well structured and organized, this is very important.
504
-
505
-
ALWAYS run `make format-rs` and `make lint-rs` after making changes to rust code and fix all suggestions to maintain code quality.
506
-
507
-
ALWAYS run `make lint-py` after making changes to python code and fix all suggestions to maintain code quality.
508
-
509
-
ALWAYS update this file when it is out of date.
510
-
511
-
NEVER add imports anywhere except at the top of the file, this applies to both python and rust.
512
-
513
-
NEVER write `unsafe` code, if you think you need to write unsafe code, explicitly ask the user or leave a `todo!()` with a suggestion and explanation.
514
-
515
531
## JavaScript Package (`monty-js`)
516
532
517
533
The JavaScript package provides Node.js bindings for the Monty interpreter via napi-rs, located in `crates/monty-js/`.
@@ -585,3 +601,25 @@ npm test
585
601
- Tests use [ava](https://github.com/avajs/ava) and live in `crates/monty-js/__test__/`
586
602
- Tests are written in TypeScript
587
603
- Follow the existing test style in the `__test__/` directory
604
+
605
+
## NOTES
606
+
607
+
ALWAYS consider code quality when adding new code, if functions are getting too complex or code is duplicated, move relevant logic to a new file.
608
+
Make sure functions are added in the most logical place, e.g. as methods on a struct where appropriate.
609
+
610
+
The code should follow the "newspaper" style where public and primary functions are at the top of the file, followed by private functions and utilities.
611
+
ALWAYS put utility, private functions and "sub functions" underneath the function they're used in.
612
+
613
+
It is important to the long term health of the project and maintainability of the codebase that code is well structured and organized, this is very important.
614
+
615
+
ALWAYS run `make format-rs` and `make lint-rs` after making changes to rust code and fix all suggestions to maintain code quality.
616
+
617
+
ALWAYS run `make lint-py` after making changes to python code and fix all suggestions to maintain code quality.
618
+
619
+
ALWAYS update this file when it is out of date.
620
+
621
+
NEVER add imports anywhere except at the top of the file, this applies to both python and rust.
622
+
623
+
NEVER write `unsafe` code, if you think you need to write unsafe code, explicitly ask the user or leave a `todo!()` with a suggestion and explanation.
624
+
625
+
When you get asked a question like "Is X really the best approach" ANSWER THE QUESTION! don't try to make a chance based on a perceived instruction in the question!
0 commit comments