Skip to content
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
20 changes: 20 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,20 @@ pub enum SandboxesCommands {
/// A tag to list it by, as name=value. Repeatable.
#[arg(long = "tag", value_name = "NAME=VALUE")]
tags: Vec<String>,

/// Reach no network at all. Not with --allow-cidr or --allow-domain.
#[arg(long, conflicts_with_all = ["allow_cidr", "allow_domain"])]
block_network: bool,

/// Reach only these IP ranges (and any --allow-domain), as a CIDR such
/// as 203.0.113.0/24. Repeatable.
#[arg(long = "allow-cidr", value_name = "CIDR")]
allow_cidr: Vec<String>,

/// Reach only these hosts (and any --allow-cidr): example.com,
/// *.example.com for it and every name under it, or *. Repeatable.
#[arg(long = "allow-domain", value_name = "DOMAIN")]
allow_domain: Vec<String>,
},

/// Run a command in a sandbox, print its output, and exit with its exit code.
Expand Down Expand Up @@ -2905,6 +2919,9 @@ pub fn run() {
env,
name,
tags,
block_network,
allow_cidr,
allow_domain,
} => commands::sandboxes::create(&commands::sandboxes::CreateArgs {
app: &app,
image_file: image_file.as_deref(),
Expand All @@ -2913,6 +2930,9 @@ pub fn run() {
env: &env,
name: name.as_deref(),
tags: &tags,
block_network,
allow_cidr: &allow_cidr,
allow_domain: &allow_domain,
}),
SandboxesCommands::Exec {
sandbox_id,
Expand Down
6 changes: 6 additions & 0 deletions src/commands/sandboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub struct CreateArgs<'a> {
pub env: &'a [String],
pub name: Option<&'a str>,
pub tags: &'a [String],
pub block_network: bool,
pub allow_cidr: &'a [String],
pub allow_domain: &'a [String],
}

/// Create a sandbox and print its ID: on stdout alone, so scripts can take it.
Expand All @@ -45,6 +48,9 @@ pub fn create(args: &CreateArgs) {
"env": pairs(args.env, "--env", "PORT=8000"),
"name": args.name,
"tags": pairs(args.tags, "--tag", "task=build"),
"block_network": args.block_network,
"outbound_cidr_allowlist": (!args.allow_cidr.is_empty()).then_some(args.allow_cidr),
"outbound_domain_allowlist": (!args.allow_domain.is_empty()).then_some(args.allow_domain),
});
if !output::is_json_mode() {
output::info(
Expand Down
40 changes: 40 additions & 0 deletions tests/sandboxes_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,46 @@ fn create_sends_what_was_asked_and_prints_only_the_id_on_stdout() {
created.assert();
}

#[test]
fn create_sends_the_network_it_may_reach_and_refuses_block_beside_an_allowlist() {
let mut server = Server::new();
let home = setup_config(&server);
let created = server
.mock("POST", "/v1/orgs/sandboxes")
.match_body(Matcher::PartialJsonString(
r#"{"block_network":false,"outbound_cidr_allowlist":["203.0.113.0/24"],"outbound_domain_allowlist":["*.github.com","pypi.org"]}"#
.to_string(),
))
.with_status(201)
.with_header("content-type", "application/json")
.with_body(format!(
r#"{{"id":"{SANDBOX}","app_id":"00000000-0000-0000-0000-000000000001","app_name":"agents"}}"#
))
.expect(1)
.create();

floo()
.args(["sandboxes", "create", "--app", "agents"])
.args(["--allow-cidr", "203.0.113.0/24"])
.args([
"--allow-domain",
"*.github.com",
"--allow-domain",
"pypi.org",
])
.env("HOME", home.path())
.assert()
.success()
.stdout(format!("{SANDBOX}\n"));
floo()
.args(["sandboxes", "create", "--app", "agents", "--block-network"])
.args(["--allow-domain", "pypi.org"])
.env("HOME", home.path())
.assert()
.failure();
created.assert();
}

#[test]
fn exec_prints_each_stream_and_exits_with_the_commands_code() {
let mut server = Server::new();
Expand Down