Skip to content

Commit a9a8e04

Browse files
committed
add proposal
1 parent 3954883 commit a9a8e04

File tree

1 file changed

+86
-0
lines changed
  • proposals/0002-hip-simplify-sandbox-creation

1 file changed

+86
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# HIP 0002 - Simplify Sandbox Creation
2+
3+
4+
## Summary
5+
6+
This is a proposal to redefine some user facing APIs for creating sandboxes.
7+
8+
## Motivation
9+
10+
Currently, our user facing API for creating sandboxes is unergonomic and forces users to worry about too much fluff that they shouldn't need to know or worry about. For example, in order to create an uninitalized sandbox, users are forced to provide 4(!) parameters, many of which are not needed in 90% of the cases. And then, they need to call `.evolve()` on it, whatever that means.
11+
```rust
12+
let mut uninitialized_sandbox = UninitializedSandbox::new(
13+
hyperlight_host::GuestBinary::FilePath(
14+
hyperlight_testing::simple_guest_as_string().unwrap(),
15+
),
16+
None, // default configuration
17+
None, // default run options
18+
None, // default host print function
19+
)?;
20+
let mut multi_use_sandbox: MultiUseSandbox = uninitialized_sandbox.evolve(Noop::default())?;
21+
22+
23+
```
24+
25+
What we should do instead is provide 2 ways of doing things.
26+
27+
1. The first way of doing should be extremly simple, with very few parameters, and sound defaults, suitable for cases where the user doesn't care about more advanced features.
28+
2. The second way should be for more advanced users, allowing additional more advanced options, should the user need it.
29+
30+
Importantly, these APIs need to be separate functions/method, so as to not force complexity where it's not wanted, like we do currently.
31+
32+
### Goals
33+
34+
- Make it easier for users to use Hyperlight
35+
- Have a simple API for basic use-cases, while still having additional options available for powerusers
36+
37+
## Design details
38+
39+
40+
### Simpler creation of Sandboxes
41+
Currently, `MultiuseSandbox` can only be created form an exiting `UninitializedSandbox`. UninitializedSandbox is "sandbox" that not yet had any initialization code run inside the sandbox. Its only purpose is to be "evolved" into a `MultiUseSandbox` with an optional transition function. The transition function is used to save state to sandbox memory, by allowing guest functions to be called **without having memory reset immediately after the function call**. In practice, this transition function is rarely used, and be removed. The exact same functionality as `evolve` can already be achived using the existing `MultiUseGuestCallContext`, together with using `finish_no_reset`.
42+
43+
I propose we remove `UninitializedSandbox` so that a Sandbox can be created in a single function call. I also propose we rename:
44+
- `MultiuseSandbox` to `Sandbox`. The name was chosen to distingish it from `SingleUseSandbox`, however `SingleUseSandbox` has since been removed.
45+
- `MultiUseContextGuestCallContext` to `SandboxContext`
46+
- `MultiUseContextCallback` to `SandboxContextCallback`
47+
48+
I propose the following signature for `Sandbox::new`
49+
50+
```rust
51+
pub fn new(guest_binary: GuestBinary) -> Result<Self>
52+
```
53+
This function would do the functionally equivalent to the current
54+
55+
```rust
56+
UninitializedSandbox::new(
57+
guest_binary,
58+
None,
59+
None,
60+
None,
61+
)?.evolve(Noop::default())?;
62+
63+
```
64+
65+
If a user would like to provide the now removed options (SandboxConfiguration, SandboxRunOptions, HostPrinterWriter), I propose we create a new SandboxBuilder:
66+
67+
```rust
68+
let mut config: SandboxConfiguration = SandboxConfiguration::new();
69+
config.with_input_data_size(1024);
70+
config.run_in_process(true);
71+
72+
let sandbox: Sandbox = SandboxBuilder::new(binary)
73+
.with_config(&config)
74+
.with_host_print_writer(|msg| println!("{}", msg))
75+
.with_host_function("sleep_5_secs", || {
76+
thread::sleep(Duration::from_secs(5));
77+
Ok(())
78+
})
79+
.build()?;
80+
```
81+
and that we remove and consolidate `SandboxRunOptions` into `SandboxConfiguration`, so we only have 1 config struct.
82+
83+
This HIP is only concerned with user facing changes.
84+
85+
86+

0 commit comments

Comments
 (0)