Skip to content

Commit 98f7ade

Browse files
authored
Improve documentation and add sample eval (#31)
* add sample eval, update missing list * more doc tweaks * cost warning * clarify subnet * add more security warning
1 parent 1c75eba commit 98f7ade

4 files changed

Lines changed: 62 additions & 10 deletions

File tree

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ as sandboxes, running within AWS EC2.
77

88
## Installing
99

10-
Add this using [Poetry](https://python-poetry.org/)
10+
Add this using [uv](https://github.com/astral-sh/uv)
1111

1212
```
13-
poetry add git+ssh://git@github.com/UKGovernmentBEIS/inspect_ec2_sandbox.git
14-
```
15-
16-
or in [uv](https://github.com/astral-sh/uv),
13+
uv add git+ssh://git@github.com/UKGovernmentBEIS/inspect_ec2_sandbox.git
14+
```
15+
or in [Poetry](https://python-poetry.org/),
1716

1817
```
19-
uv add git+ssh://git@github.com/UKGovernmentBEIS/inspect_ec2_sandbox.git
18+
poetry add git+ssh://git@github.com/UKGovernmentBEIS/inspect_ec2_sandbox.git
2019
```
2120

21+
2222
## AWS Infrastructure
2323

2424
This plugin depends on certain infrastructure existing already. See the [infra docs](infra/README.md) for a
@@ -133,13 +133,31 @@ sandbox=SandboxEnvironmentSpec("ec2", Ec2SandboxEnvironmentConfig.from_settings(
133133

134134
See [schema.py](src/ec2sandbox/schema.py) for details.
135135

136+
## Compatibility with existing Inspect evals
137+
138+
This sandbox provider is not [Dockerfile-compatible](https://inspect.aisi.org.uk/sandboxing.html#environment-binding).
139+
Hence, you will have to rebuild your evaluation envionment on top of an AWS virtual machine AMI.
140+
141+
It is not a drop-in replacement; passing `--sandbox ec2` is unlikely to work for an existing eval.
142+
143+
## Sample evaluation
144+
145+
You can look at an existing [sample eval](src/ec2sandbox/examples/where_am_i.py) for how to get started.
146+
147+
A more complex eval is [Sandbox Escape Bench](https://github.com/UKGovernmentBEIS/sandbox_escape_bench), where this EC2 sandbox is used as an outer sandbox and the agent is tasked with escaping an inner sandbox, generally Docker or Kubernetes.
148+
149+
## Sandboxing limitations
150+
151+
A sandbox is not a magic bullet for AI agent security. For more background, read AISI's [Inspect Sandboxing Toolkit](https://github.com/UKGovernmentBEIS/aisi-sandboxing).
152+
153+
For the EC2 sandbox specifically, beware that the IAM role used by the sandbox EC2 instance (which is required by this provider for communication) can also be used by the agent.
154+
155+
136156
## Tech Debt / Missing features
137157

138-
- task_cleanup is not implemented; only the default sample_cleanup is, so if you Ctrl-C a run, you have to clean up with the CLI command
139158
- Move long-running AWS commands to a separate thread to avoid blocking Inspect's TUI
140-
- Integration testing of all features
141-
- Add more sample evals
142159
- better logging/tracing
160+
- Dockerfile-compatibility
143161

144162

145163
## Developing

infra/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
This folder contains a CDK project that allows you to deploy a basic VPC for
44
use by Inspect EC2 sandboxes.
55

6+
**WARNING**: This stack will result in ongoing AWS charges even when you have no sandboxes active: as of July 2026, around $60/month.
7+
68
## Architecture
79

810
It creates a VPC with three subnets, all in a single AZ.
911

10-
One of the subnets is completely isolated from the internet, the other is private with outgoing internet access.
12+
One of the subnets is completely isolated from the internet, the other is private with outgoing internet access. (The third is used only for the NAT gateway, not sandbox VMs.)
1113

1214
It creates an S3 bucket which is needed for data communication with sandbox EC2 instances.
1315

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Runnable sample evals for the EC2 sandbox provider."""
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Sample eval: have the agent work out which EC2 instance it is running on."""
2+
3+
from inspect_ai import Task, task
4+
from inspect_ai.dataset import Sample
5+
from inspect_ai.scorer import match
6+
from inspect_ai.solver import basic_agent
7+
from inspect_ai.tool import bash
8+
from inspect_ai.util import SandboxEnvironmentSpec
9+
10+
from ec2sandbox.schema import Ec2SandboxEnvironmentConfig
11+
12+
INSTANCE_TYPE = "t3a.small"
13+
14+
PROMPT = """\
15+
You are running inside a virtual machine on AWS. Work out what \
16+
type of virtual machine you are on, and submit its instance type identifier \
17+
(for example, "m5.xlarge")."""
18+
19+
20+
@task
21+
def where_am_i() -> Task:
22+
"""Ask the agent to discover and report its own EC2 instance type."""
23+
return Task(
24+
dataset=[Sample(input=PROMPT, target=INSTANCE_TYPE)],
25+
solver=basic_agent(tools=[bash(timeout=60)], message_limit=20),
26+
scorer=match(location="exact"),
27+
sandbox=SandboxEnvironmentSpec(
28+
"ec2",
29+
Ec2SandboxEnvironmentConfig.from_settings(instance_type=INSTANCE_TYPE),
30+
),
31+
)

0 commit comments

Comments
 (0)